Jump to content

Stream

Members
  • Posts

    58
  • Joined

  • Last visited

Stream's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. it gives me an error like: Table 'jsalon.resource' doesn't existbut jsalon is the name of my database why it sees like table? thank you
  2. 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 thank you
  3. if(mysql_num_rows($result)>0) this is the changes I've done and it worked fine thank you!
  4. but what should I change to make it work! Should i write here something like if($result>0) & if($result not=1) Thank you
  5. 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); ?>
  6. I think you should use quote birthyear<"1995"
  7. $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
  8. Thank you Ive just misplased model and mark It's ok now!
  9. but should we use mysql_real_escape_string when we add image path to db or there is no matter for that? Thank you
  10. Don Eyeh! thank you that was my silly mistake!
  11. 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
  12. Sorry justsomeguy but what do you mean by saying $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
  13. 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
  14. 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
×
×
  • Create New...