Jump to content

Stream

Members
  • Posts

    58
  • Joined

  • Last visited

Posts posted by Stream

  1. I could find an example for pagination like bellow and like to implement it to my query.

    <?phpif (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; };$start_from = ($page-1) * 20;$sql = "SELECT * FROM students ORDER BY name ASC LIMIT $start_from, 20";$rs_result = mysql_query ($sql,$connection);?><table><tr><td>Name</td><td>Phone</td></tr><?phpwhile ($row = mysql_fetch_assoc($rs_result)) {?>			<tr>			<td><? echo $row["Name"]; ?></td>			<td><? echo $row["PhoneNumber"]; ?></td>			</tr><?php};?></table><?php$sql = "SELECT COUNT(Name) FROM students";$rs_result = mysql_query($sql,$connection);$row = mysql_fetch_row($rs_result);$total_records = $row[0];$total_pages = ceil($total_records / 20); for ($i=1; $i<=$total_pages; $i++) {			echo "<a href='pagination.php?page=".$i."'>".$i."</a> ";};?>

    My query is like bellow

    if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; };$start_from = ($page-1) * 3;$result = mysql_query("SELECT * FROM `add_new_car` AS a INNER JOIN `image_add_car` AS b ON				 a.id_add_car = b.user_id WHERE (b.user_id, b.id_image_add_car) IN (SELECT user_id, MIN(id_image_add_car)	FROM image_add_car GROUP BY user_id) AND ".$whereclause." ORDER BY a.id_add_car desc LIMIT $start_from, 3");

    Here in the code I made some changes like bellow

    <?php$sql = "SELECT COUNT(*)  FROM {$result}";$rs_result = mysql_query($sql);$row = mysql_fetch_row($rs_result);				  this is the line 1610$total_records = $row[0];$total_pages = ceil($total_records / 3); for ($i=1; $i<=$total_pages; $i++) {			echo "<a href='index.php?page=".$i."'>".$i."</a> ";};mysql_close($connection);?>

    but gives me an error message

    Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in F:\home\je\www\search.php on line 1610
    thank you
  2. Can you help me please why It doesn't echo "No date like that"; when there is no date like I search.

    if($result>0) { while($row = mysql_fetch_array($result))   {  echo "<table border='1' align=center style='width: 750px;'  bordercolor=#CC99FF ><tr><th>Foto</th><th>Type</th><th>Description</th>  </tr>";  echo "<tr>";    echo "<td width='150'> <img src='" .$row['big'] ."' style='width: 150px; height: 100px; ' /></td>";   echo "<td class=search>" ."Mark:        ". htmlentities($row['mark'], ENT_QUOTES)  ."<br>"               ."Model:       ". htmlentities($row['model'], ENT_QUOTES) . "<br>"  ."Year:  ". htmlentities($row['year'], ENT_QUOTES)  . "<br>" ."Price:         ". htmlentities($row['price'], ENT_QUOTES) . "<br>" ."Run:       ". htmlentities($row['run_km'], ENT_QUOTES). "<br>"              ."Color:         ". htmlentities($row['color'], ENT_QUOTES) . "</td>";     echo '<td width="380" class=search><a href="view.php?rmsd='.$row['id_add_car'].'&xlxs=' .$row['id_image_add_car'].'">' .$row['description'].'</a>' ."<br>"."<br>"         ."Name:       "."/ ". htmlentities($row['name'], ENT_QUOTES)   ."/"."<br>" ."Number:      " . htmlentities($row['mobile'], ENT_QUOTES) .'</td>';               echo "</tr>";  echo ("<br />");   } echo "</table>";  }  else  [b]echo "No date like that";[/b] { print mysql_error(); }   mysql_close($connection); ?>

  3. $where = array();$whereclause = '';if (!empty($mark)) {    $where[] = "a.mark = '$mark'";}if (!empty($mark)) {    $where[] = "a.model = '$model'";}if (!empty($year)) {    $where[] = "a.year = '$year'";}if (count($where > 0)) {    $whereclause = join(' AND ', $where);}

    how to implement else statement in case of $where[] = "a.mark = '$model'"; = 0to show by default "Toyota" I think should be something like else $whereclause = join(' AND ', $where(Toyota)); Thank you

  4. I am fetching date from db but there is no result for some date.For example

    <td><?php echo $max_first["mark"]; ?></td> 

    is ok but

    <td><?php $max_first["change_car"]; ?></td> 

    returns an empty field. Even both of them varchar(255) cp1251_general_ci thank you

  5. Sorry justsomeguy but what do you mean by saying

    Print out the final query to see what it says
    $result = mysql_query("SELECT * FROM `add_new_car` AS a INNER JOIN `image_add_car` AS b ON								 a.id_add_car = b.user_id WHERE (b.user_id, b.id_image_add_car) IN (SELECT user_id, MIN(id_image_add_car)	  FROM image_add_car GROUP BY user_id) AND ".$whereclause." ORDER BY a.id_add_car");

    the code returns me result just when I select at least Mark and Model

  6. I think the problem is in my query string because when I refresh the search page it gives me an error lik : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY a.id_add_car' at line 5

  7. I was recomended to use the code as bellow to check if one of the condition not selected for example what if somebody will select just Mark=toyota and will leave empty Model and Year.

    $where = array();$whereclause = '';if (!empty($mark)) {    $where[] = "a.mark = '$mark'";}if (!empty($model)) {    $where[] = "a.model = '$model'";}if (!empty($year)) {    $where[] = "a.year = $year";}if (count($where > 0)) {    $whereclause = join(' AND ', $where);}

    $result = mysql_query("SELECT * FROM `add_new_car` AS a INNER JOIN `image_add_car` AS b ON				 a.id_add_car = b.user_id WHERE (b.user_id, b.id_image_add_car) IN (SELECT user_id, MIN(id_image_add_car)	FROM image_add_car GROUP BY user_id) AND ".$whereclause." ORDER BY a.id_add_car");

    Mark=toyota Model=Prado Year=2013But why when I chose just Mark it doesn't gives me any result but at least together with Model=Prado it works without selecting YearThank you

  8. Is it correct to pass mysql_real_escape_string to variable like$year =mysql_real_escape_string( trim($_POST['year'])); or correct to use it in query like bellow$year =( trim($_POST['year'])); $sql = "INSERT INTO table (year) values ( . mysql_real_escape_string($value) .)

  9. $result = mysql_query("SELECT * FROM `add_new_car` AS a INNER JOIN `image_add_car` AS b ON a.id_add_car = b.user_id WHERE a.id_add_car =b.user_id and a.mark='$model' and a.model='$mark' and a.year='$year' ORDER BY a.id_add_car");

    I am sorry but this gives me the same result

  10. This is the code using which I am selecting date from two table first add_new_car keeps date and the second image_add_car keeps image path(like shown bellow)

    $result = mysql_query("SELECT * FROM `add_new_car`,`image_add_car` where id_add_car = user_id and mark='$model' and model='$mark' and year='$year'ORDER BY image_id_add_car");

    id_image_add_car-------user_id 602 --------- 386 2 images/1365172947.jpg images/small_1365172947.jpg 601 --------- 386 2 images/1365172945.jpg images/small_1365172945.jpg 600 --------- 386 2 images/1365172942.jpg images/small_1365172942.jpg 599 --------- 386 2 images/1365172940.jpg images/small_1365172940.jpg 598 --------- 384 2 images/1365172691.jpg images/small_1365172691.jpg 597 --------- 384 2 images/1365172688.jpg images/small_1365172688.jpg 596 --------- 384 2 images/1365172685.jpg images/small_1365172685.jpg 595 --------- 384 2 images/1365172683.jpg images/small_1365172683.jpg 594 --------- 384 2 images/1365172679.jpg images/small_1365172679.jpg 593 --------- 384 2 images/1365172677.jpg images/small_1365172677.jpg
    And I can get something like shown bellow it shows the picture and date but insted of one the whole amount of user_id for example (386) 4 of them then it echo another date with his pictures and so on 3260eb4252a3.jpg What's the way to limit amount of user_idCan you help me here
  11. I have changed the query string like bellow and it worked as I needed ! $sql = mysql_query(SELECT id_add_car,model,date FROM add_new_car); 424---308---images/1363209424.jpg423---308---images/1363209421.jpg422---308---images/1363209418.jpg421---308---images/1363209416.jpg but I got a question what if a few user at once will enter date Will it work correct? Thank you

×
×
  • Create New...