liam1412 Posted January 28, 2007 Share Posted January 28, 2007 [code]$last_cars = "SELECT * FROM last_cars WHERE userid='$userid' ORDER BY car_id ASC"; [/code]Just echoing em out random when im using a while loop to go through the result set. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 28, 2007 Share Posted January 28, 2007 It looks fine. By random, you mean every time you load it they're in a different order? Post the rest of your code.` Quote Link to comment Share on other sites More sharing options...
liam1412 Posted January 28, 2007 Author Share Posted January 28, 2007 It is a very long script for quite a detailed profile page. you want it all Quote Link to comment Share on other sites More sharing options...
liam1412 Posted January 28, 2007 Author Share Posted January 28, 2007 Will this bit do. Its my first scropt so go easy. lol [code]<?php $last_cars = "SELECT * FROM last_cars WHERE userid='$userid' ORDER BY car_id ASC"; $last_query = mysql_query($last_cars);$no_cars = mysql_num_rows($last_query);?><div class="last5"><table width="396" cellpadding="6" cellspacing="1"><tr><td class="header2" colspan="4" bgcolor="#565656">Previous Cars - <?php if($username == $_SESSION['username']){echo ?><a href="edit_last5.php?userid=<?php echo $userid?>">Change</a><?php } ?></td></tr><tr><td class="grey" colspan="4" width="400" bgcolor="#6d6d6d">Love em or hate. Your last 5 cars. BE HONEST!!!</td></tr><tr><td class="header3" width="50" bgcolor="#6d6d6d">Year</td><td class="header3" width="150" bgcolor="#6d6d6d">Make</td><td class="header3" width="150" bgcolor="#6d6d6d">Model</td><td class="header3" width="45" bgcolor="#6d6d6d">Engine</td></tr><?phpwhile($car_result = mysql_fetch_array($last_query)){$plate = $car_result['plate']; $make = $car_result['make'];$model = $car_result['model'];$engine = $car_result['engine'];?><tr><td class="grey" width="50" bgcolor="#6d6d6d"><?php echo $plate; ?></td><td class="grey" width="150" bgcolor="#6d6d6d"><?php echo $make; ?></td><td class="grey" width="150" bgcolor="#6d6d6d"><?php echo $model; ?></td><td class="grey" width="45" bgcolor="#6d6d6d"><?php echo $engine; ?></td></tr><?php}?></table>[/code] Quote Link to comment Share on other sites More sharing options...
liam1412 Posted January 28, 2007 Author Share Posted January 28, 2007 Figured it. Sorry to bother you. For some strange reason im using one query in the head for selecting and this one further down for counting. Why I do not know. Quote Link to comment Share on other sites More sharing options...
liam1412 Posted January 28, 2007 Author Share Posted January 28, 2007 It int solved after all. Any clues Quote Link to comment Share on other sites More sharing options...
liam1412 Posted January 28, 2007 Author Share Posted January 28, 2007 I also have a query that deletes the oldest one if there are more than 5. Just in case you need it[code]<?phpsession_start();$userid = $_GET['userid'];$plate = $_POST['plate'];$make = $_POST['make'];$model = $_POST['model'];$engine = $_POST['engine'];$host = 'localhost';$db_username = 'root';$db_password = '';$db_name = 'klubdeutsch';mysql_connect("$host" , "$db_username" , "$db_password")or die("Cannot Connect to Server");mysql_select_db("$db_name")or die("Cannot connect to Databse");$last5 = "SELECT * FROM last_cars WHERE userid='$userid'";$last5_query = mysql_query($last5);$total = mysql_num_rows($last5_query);if($total == 5){$oldest_car = "SELECT * FROM last_cars WHERE userid='$userid' ORDER BY car_id ASC LIMIT 1";$query = mysql_query($oldest_car);$result = mysql_fetch_array($query);$car_id = $result['car_id'];$delete_oldest = "DELETE FROM last_cars WHERE car_id='$car_id'";$query = mysql_query($delete_oldest)or die('Dint Work');}$add_new = ("INSERT INTO last_cars (userid, plate, make, model, engine) values('$userid' , '$plate' , '$make' , '$model' , '$engine')")or die('Dint Work 2');$add_car = mysql_query($add_new); if($add_car){header("location:profile2.php?userid=$userid");}else{echo broke;}?>[/code] Quote Link to comment Share on other sites More sharing options...
trq Posted January 28, 2007 Share Posted January 28, 2007 What is your question again? You seem to have veered off topic. Quote Link to comment Share on other sites More sharing options...
liam1412 Posted January 28, 2007 Author Share Posted January 28, 2007 I have a form that users can add a car to the list on there profile. if there is more then 5 it deletes the last one and replaces it with the new one. I want that one to remain on top but its ending up wherever it feels like. The first bit of code is the display of the list. the second bit adds to the list and deletws if neccessary. Quote Link to comment Share on other sites More sharing options...
liam1412 Posted January 28, 2007 Author Share Posted January 28, 2007 **bump** Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.