Free2Code
The majority of forums are now only available as archives, which means posting/editing is disabled.

The Anything and Everything forum is still open.
 
Time: 2013-05-18, 10:19am
Whats wrong with this please
Subject: Whats wrong with this please  ·  Posted: 2004-12-01, 02:31am
Rank: ? (53)
Member #: 16444
The result im getting is "Query is Empty"

any ideas pls?
(there is deffinately values in the database that are correct.)


Code:
  1. <?php
  2. include ('check_login.php');
  3. $name = $_SESSION['username'];
  4. $query = mysql_query("SELECT USERNAME, PERCENT FROM burnleycollege_mod1_results WHERE CANDIDATE_USERNAME='$name'");
  5. $result = mysql_query($query) or die(mysql_error());
  6. echo "<table>";
  7. while ($row = mysql_fetch_array($result))
  8. {
  9. $username = $row['username'];
  10. $percent = $row['percent'];
  11. echo "<tr><td>$username</td>
  12.           <td>$percent</td></tr>";
  13. }
  14. echo "</table>";
  15. ?>


» Post edited 2004-12-01, 02:32am by Elliott.

 
  Reply to this ·  Post link ·  Top
Subject: Re: Whats wrong with this please  ·  Posted: 2004-12-01, 06:40am
Rank: ? (900)
Member #: 3
Code:
  1. <?
  2. $query = mysql_query("SELECT USERNAME, PERCENT FROM burnleycollege_mod1_results WHERE CANDIDATE_USERNAME='".$name."'");
  3. ?>


line #9 reads: $result = mysql_query($query) or die(mysql_error());

you could just do like this:

if (!$query) die('query failed: '.mysql_error());

then go on to

while ($row = mysql_fetch_array($query))

» Post edited 2004-12-01, 06:46am by bs0d.

--bs0d | allsyntax.com
 
  Reply to this ·  Post link ·  Top
Subject: Re: Whats wrong with this please  ·  Posted: 2004-12-01, 01:24pm
Rank: ? (768)
Member #: 11085
ur code should be (for maximum optimization)
Code:
  1. <?php
  2. include ('check_login.php');
  3. $name = $_SESSION['username'];
  4. $query = mysql_query("SELECT USERNAME, PERCENT FROM burnleycollege_mod1_results WHERE CANDIDATE_USERNAME='".$name."'") or die(mysql_error());
  5. ?>
  6. <table>
  7. <?php
  8. while ($row = mysql_fetch_array($query)){
  9.     ?>
  10.     <tr><td><?=$row['username']?></td>
  11.     <td><?=$row['percent']?></td></tr>
  12.     <?php
  13. }
  14. ?>
  15. </table>


your problem was you were trying to call a query using the result of a query (qhih is just a pointer) whcih cannot work.

» Post edited 2004-12-01, 01:41pm by relpats_eht.

- relpats_eht
 
  Reply to this ·  Post link ·  Top

Pages: 1

Please login or register to post a reply.

Penguino AVR

Want to learn about robotics or microcontrollers?
Check out the Penguino AVR from our friends at
Icy Labs