Jump to content

Can not pull information that I need from Mysql...


Collegeboox

Recommended Posts

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.

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.