Collegeboox Posted February 19, 2011 Share Posted February 19, 2011 On the home page I am having a problem pulling information from the MySql here is my code...and this is what I am trying to do... i am trying to pull 10 items from the database that have today's date...I am also trying to make the user name a link to a page called backpack.php where that page can use the user name that is clicked to retrieve more information. (the problem I am having is 10 results come up but it is a repeat of the same 10 results and when you click the link it doesn't show the user that is clicked info.) PLEASE someone help I have been trying to figure this out for the longest time. <form action="backpack.php" method="post"> <?php // rows to return $limit=10; $idcount=10; $date = date('Y-m-d'); $count = 0; while ($limit>=$count) { //open database $connect = mysql_connect("hostname","uname","pass") or die("Not connected"); mysql_select_db("db_name") or die("could not log in"); $query = "SELECT *,COUNT(name) FROM boox WHERE date='$date' ORDER BY date"; $idcount = $row['COUNT(name)']; $result = mysql_query($query); while($row = mysql_fetch_array($result)) echo "</br><table width='297' height='200' border='1' align='center' style='overflow:scroll'> <tr> <td width='152'>Book Title:</td> <td width='129'>$row[name]</td> </tr> <tr> <td>Author:</td> <td>$row[author]</td> </tr> <tr> <td>ISBN#</td> <td>$row[isbn]</td> </tr> <tr> <td>Date Posted:</td> <td>$row[date]</td> </tr> <tr> <td>Posted By:</td> <td><a href='backpack.php' onclick='document['packback'].submit()'>$row[username]</a></td> </tr> <tr> <td>School:</td> <td>$row[school]</td> </tr> </table></br>"; $count = $count + 1; $idcount = idcount + 1; } ?> </form> MOD EDIT: DB credentials removed, . . . tags added. Quote Link to comment https://forums.phpfreaks.com/topic/228181-can-not-pull-information-that-i-need-from-mysql/ Share on other sites More sharing options...
Pikachu2000 Posted February 19, 2011 Share Posted February 19, 2011 I've taken the liberty of removing your DB credentials, but it would probably still be a good idea to change the password for the database. Also, when posting code, please enclose it within the forum's . . . BBCode tags. Quote Link to comment https://forums.phpfreaks.com/topic/228181-can-not-pull-information-that-i-need-from-mysql/#findComment-1176723 Share on other sites More sharing options...
Muddy_Funster Posted February 19, 2011 Share Posted February 19, 2011 not sure what the issue actualy is... are you getting the same result 10 times, or the same 10 different results each time you run the query? is there a reason that you have the result set limited to 10 in the php code rather than the SQL? <td><a href='backpack.php' onclick='document['packback'].submit()'>$row[username]</a></td> what is packback in relation to? is there a reason you are using javascript? $idcount = idcount + 1; this line is broken, not that it matters as you assign the value to $idcount each time you run through the while loop anyway. Quote Link to comment https://forums.phpfreaks.com/topic/228181-can-not-pull-information-that-i-need-from-mysql/#findComment-1176778 Share on other sites More sharing options...
Collegeboox Posted February 19, 2011 Author Share Posted February 19, 2011 I am getting the same result 10 times, and about that java script I do not know what it is saying I do not use java that much. I am trying to make the user name a link and when it is clicked send to user name to a page called backpack.php so when that page is opened up (backpack.php) it shows the persons name that was clicked on and pulls other information from the DB according to their name. Quote Link to comment https://forums.phpfreaks.com/topic/228181-can-not-pull-information-that-i-need-from-mysql/#findComment-1176804 Share on other sites More sharing options...
BlueSkyIS Posted February 19, 2011 Share Posted February 19, 2011 "Java" is to "Javascript" about the same as "fun" is to "funeral". Quote Link to comment https://forums.phpfreaks.com/topic/228181-can-not-pull-information-that-i-need-from-mysql/#findComment-1176805 Share on other sites More sharing options...
Muddy_Funster Posted February 19, 2011 Share Posted February 19, 2011 Right then, your problem with the result set is that the scrip is simply calling the same querie 10 times. because you didn't open the { for the second while() then it couldn't run the condition for that properly. If you had included that you would have got 10 coppies of a table listing every entry for that date. Kill the Javascript, if you don't know what it's doing, don't have it in your page. try something along the following lines : <form action="backpack.php" method="post"> <?php // rows to return // $limit=10; **not used any more // $idcount=10; **not used any more $date = date('Y-m-d'); // $count = 0; **not used any more //while ($limit>=$count) **not used any more // { **not used any more //open database $connect = mysql_connect("hostname","uname","pass") or die("Not connected"); mysql_select_db("db_name") or die("could not log in"); $query = "SELECT *,COUNT(name) FROM boox WHERE date='$date' ORDER BY date LIMIT 10"; // use the SQL to limit the 10 results // $idcount = $row['COUNT(name)']; **not used any more // $result = mysql_query($query); **not used any more while($row = mysql_fetch_array($result)) { echo "</br><table width='297' height='200' border='1' align='center' style='overflow:scroll'> <tr> <td width='152'>Book Title:</td> <td width='129'>$row[name]</td> </tr> <tr> <td>Author:</td> <td>$row[author]</td> </tr> <tr> <td>ISBN#</td> <td>$row[isbn]</td> </tr> <tr> <td>Date Posted:</td> <td>$row[date]</td> </tr> <tr> <td>Posted By:</td> <td><a href='backpack.php?usr=".$row[username]."</a></td> </tr> <tr> <td>School:</td> <td>$row[school]</td> </tr> </table></br>"; // $count = $count + 1; **not used any more // $idcount = idcount + 1; **not used any more } ?> </form> then stick the following line near the top of backpack.php $userName = $_GET['usr']; echo $userName; Quote Link to comment https://forums.phpfreaks.com/topic/228181-can-not-pull-information-that-i-need-from-mysql/#findComment-1176834 Share on other sites More sharing options...
Collegeboox Posted February 19, 2011 Author Share Posted February 19, 2011 Thank you muddy... the php limit worked like a charm however on the backpack.php page it isnt echoing username Quote Link to comment https://forums.phpfreaks.com/topic/228181-can-not-pull-information-that-i-need-from-mysql/#findComment-1176848 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.