•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 401,422 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,908 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 728 | Replies: 31 | Solved
![]() |
•
•
Join Date: Mar 2008
Posts: 85
Reputation:
Rep Power: 1
Solved Threads: 0
I'm trying pull up data from database, and display it on a table. I used this code before but for some reason it won't work here. Any suggestions? Thanks!
It says the error is this line:
The error message is: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /Users/laurenyoung/Sites/runners.php on line 60
It says the error is this line:
<?php while ($list = mysql_fetch_assoc($result)) {?>
The error message is: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /Users/laurenyoung/Sites/runners.php on line 60
<?php
// Include connection to your database
$con = mysql_connect("","","");
mysql_select_db("RUNNERS", $con);
$name = $_POST['name'];
$query = "SELECT * FROM runners WHERE id = '$name'";
$result = mysql_query($query);?>
<table class="sortable">
<!-- Table Header -->
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>1 Mile</th>
<th>2 Mile</th>
<th>5k</th>
<th>8k</th>
<th>10k</th>
<th>15k</th>
<th>20k</th>
<th>13.1</th>
<th>25k</th>
<th>26.2</th>
</tr>
</thead>
<!-- Table body-->
<tbody>
<?php while ($list = mysql_fetch_assoc($result)) {?>
<tr>
<th><?php echo $list['first_name'] ?></th>
<th><?php echo $list['last_name'] ?></th>
<th><?php echo $list['1_mile'] ?></th>
<th><?php echo $list['2_mile'] ?></th>
<th><?php echo $list['5k'] ?></th>
<th><?php echo $list['8k'] ?></th>
<th><?php echo $list['10k'] ?></th>
<th><?php echo $list['15k'] ?></th>
<th><?php echo $list['20k'] ?></th>
<th><?php echo $list['half'] ?></th>
<th><?php echo $list['25k'] ?></th>
<th><?php echo $list['full'] ?></th>
</tr>
<?php } ?>
</tbody>
</table>•
•
Join Date: Apr 2008
Location: Lahore, Pakistan
Posts: 36
Reputation:
Rep Power: 1
Solved Threads: 1
try to use
instead of,
php Syntax (Toggle Plain Text)
<?php while ($list = mysql_fetch_array($result)) {?>
instead of,
php Syntax (Toggle Plain Text)
<?php while ($list = mysql_fetch_assoc($result)) {?>
Last edited by mustafaneguib : Jul 24th, 2008 at 6:50 pm.
•
•
Join Date: Mar 2008
Posts: 85
Reputation:
Rep Power: 1
Solved Threads: 0
Still got the same error, but thanks for trying. Perhaps it's something wrong with the code I use on the initial page, which looks like this:
Thanks again!
<form action="runners.php" method="post"> <label for="first_name" style="font-size: 14px; margin-top: 10px; font-weight: bold; font-variant: small-caps;">First Name:</label> <input type="text" name="name" value="" maxlength="30" style="width:49.6%; font-size: 30px;"<br /><?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?><br /></p> <label for="last_name" style="font-size: 14px; margin-top: 10px; font-weight: bold; font-variant: small-caps;">Last Name:</label> <input type="text" name="storeid" value="" maxlength="30" style="width:49.6%; font-size: 30px;"<br /><?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?><br /></p> <form method="post" action="runners.php"> <input type="submit" style="width:90px; height: 35px; margin-left: 260px; -moz-border-radius: 10px;" name="submit" value="get info"> </form>
Thanks again!
•
•
Join Date: Mar 2008
Posts: 85
Reputation:
Rep Power: 1
Solved Threads: 0
Well I got it to come up with no errors, but it's not pulling the data:
Thanks for any help!
<form action="runners.php" method="post"> <label for="first_name" style="font-size: 14px; margin-top: 10px; font-weight: bold; font-variant: small-caps;">First Name:</label> <input type="text" name="first_name" value="" maxlength="30" style="width:49.6%; font-size: 30px;"<br /><?php if (isset($_POST['first_name'])) echo $_POST['first_name']; ?><br /></p> <label for="last_name" style="font-size: 14px; margin-top: 10px; font-weight: bold; font-variant: small-caps;">Last Name:</label> <input type="text" name="storeid" value="" maxlength="30" style="width:49.6%; font-size: 30px;"<br /><?php if (isset($_POST['last_name'])) echo $_POST['last_name']; ?><br /></p> <form method="post" action="runners.php">
<?php
// Include connection to your database
$con = mysql_connect("localhost","root","");
mysql_select_db("RUNNERS", $con);
$name = $_POST['first_name'];
$query = "SELECT * FROM runners WHERE id = '$name'";
$result = mysql_query($query);?>
<table class="sortable">
<!-- Table Header -->
<thead>
<tr>
<th>ID #</th>
<th>First Name</th>
<th>Last Name</th>
<th>1 Mile</th>
<th>2 Mile</th>
<th>5k</th>
<th>8k</th>
<th>10k</th>
<th>20k</th>
<th>13.1</th>
<th>26.2</th>
</tr>
</thead>
<!-- Tabel body-->
<tbody>
<?php while ($list = mysql_fetch_assoc($result)) {?>
<tr>
<th><?php echo $list['first_name'] ?></th>
<th><?php echo $list['last_name'] ?></th>
<th><?php echo $list['one'] ?></th>
<th><?php echo $list['two'] ?></th>
<th><?php echo $list['five'] ?></th>
<th><?php echo $list['ten'] ?></th>
<th><?php echo $list['fifteen'] ?></th>
<th><?php echo $list['twenty'] ?></th>
<th><?php echo $list['half'] ?></th>
<th><?php echo $list['full'] ?></th>
</tr>
<?php } ?>
</tbody>
</table>Thanks for any help!
•
•
Join Date: Jun 2008
Location: hyderabad,india
Posts: 95
Reputation:
Rep Power: 1
Solved Threads: 11
•
•
Join Date: Jul 2008
Location: Hyderabad,India.
Posts: 534
Reputation:
Rep Power: 2
Solved Threads: 53
change this :
To:
php Syntax (Toggle Plain Text)
$query = "SELECT * FROM runners WHERE id = '$name'";
To:
php Syntax (Toggle Plain Text)
$query = "SELECT * FROM runners WHERE id =".$name;
Champions Are Not SuperNatural,They Just Fought For One More Second When Every One Else Quit...Some times That One Second Of Effort Gives You The VICTORY...
•
•
Join Date: Mar 2008
Posts: 85
Reputation:
Rep Power: 1
Solved Threads: 0
1. Looks like I'm connecting fine. I added the die function.
2. I changed
Here's how I have the code as it stands now:
That's the only error I'm receiving, however. I would like to have the user enter his/her first and last name to pull the data. I thought that was how I had it written, but it is still, obviously, given me trouble.
Thanks!
2. I changed
$query = "SELECT * FROM runners WHERE id = '$name'"; to $query = "SELECT * FROM runners WHERE id =".$name; , but I'm receiving this error: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /Users/laurenyoung/Sites/runners.php on line 67. Line 67 = <?php while ($list = mysql_fetch_assoc($result)) ?>
Here's how I have the code as it stands now:
<?php
// Include connection to your database
$con = mysql_connect("localhost","root","");
mysql_select_db("RUNNERS", $con);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$name = $_POST['first'];
$query = "SELECT * FROM runners WHERE id =".$name;
$result = mysql_query($query);?>
<table class="sortable">
<!-- Table Header -->
<thead>
<tr>
<th>ID #</th>
<th>First Name</th>
<th>Last Name</th>
<th>1 Mile</th>
<th>2 Mile</th>
<th>5k</th>
<th>8k</th>
<th>10k</th>
<th>20k</th>
<th>13.1</th>
<th>26.2</th>
</tr>
</thead>
<!-- Table body-->
<tbody>
<?php while ($list = mysql_fetch_assoc($result)) ?>
<tr>
<th><?php echo $list['first_name'] ?></th>
<th><?php echo $list['last_name'] ?></th>
<th><?php echo $list['one'] ?></th>
<th><?php echo $list['two'] ?></th>
<th><?php echo $list['five'] ?></th>
<th><?php echo $list['ten'] ?></th>
<th><?php echo $list['fifteen'] ?></th>
<th><?php echo $list['twenty'] ?></th>
<th><?php echo $list['half'] ?></th>
<th><?php echo $list['full'] ?></th>
</tr>
</tbody>
</table>That's the only error I'm receiving, however. I would like to have the user enter his/her first and last name to pull the data. I thought that was how I had it written, but it is still, obviously, given me trouble.
Thanks!
•
•
Join Date: Jul 2008
Location: Hyderabad,India.
Posts: 534
Reputation:
Rep Power: 2
Solved Threads: 53
so you dont have any colums with that name $_POST['first'] in you table...
first execute your query in mysql with the same name,and put in your php page...
first execute your query in mysql with the same name,and put in your php page...
Champions Are Not SuperNatural,They Just Fought For One More Second When Every One Else Quit...Some times That One Second Of Effort Gives You The VICTORY...
•
•
Join Date: Jun 2008
Location: Phoenix, AZ
Posts: 599
Reputation:
Rep Power: 2
Solved Threads: 53
put in more die functions.
I agree with Shanti, there is something wrong with your query and this should tell you what it is.
php Syntax (Toggle Plain Text)
<?php // Include connection to your database $con = mysql_connect("localhost","root","") or die(mysql_error());; mysql_select_db("RUNNERS", $con) or die(mysql_error()); $name = $_POST['first']; $query = "SELECT * FROM runners WHERE id =".$name; $result = mysql_query($query) or die(mysql_error());?> <table class="sortable"> <!-- Table Header --> <thead> <tr> <th>ID #</th> <th>First Name</th> <th>Last Name</th> <th>1 Mile</th> <th>2 Mile</th> <th>5k</th> <th>8k</th> <th>10k</th> <th>20k</th> <th>13.1</th> <th>26.2</th> </tr> </thead> <!-- Table body--> <tbody> <?php while ($list = mysql_fetch_assoc($result)) ?> <tr> <th><?php echo $list['first_name'] ?></th> <th><?php echo $list['last_name'] ?></th> <th><?php echo $list['one'] ?></th> <th><?php echo $list['two'] ?></th> <th><?php echo $list['five'] ?></th> <th><?php echo $list['ten'] ?></th> <th><?php echo $list['fifteen'] ?></th> <th><?php echo $list['twenty'] ?></th> <th><?php echo $list['half'] ?></th> <th><?php echo $list['full'] ?></th> </tr> </tbody> </table>
I agree with Shanti, there is something wrong with your query and this should tell you what it is.
Last edited by R0bb0b : Jul 25th, 2008 at 12:49 am.
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss
•
•
Join Date: Apr 2008
Location: Lahore, Pakistan
Posts: 36
Reputation:
Rep Power: 1
Solved Threads: 1
i think ive found the problem. ur using while loop when your only looking for one (as far as i can see) record. so remove the while statement, and use the following,
instead of it because your problem lies in this line.
php Syntax (Toggle Plain Text)
$list=mysql_fetch_array($result);
php Syntax (Toggle Plain Text)
<!-- Table body--> <tbody> <?php $list=mysql_fetch_array($result); ?> //change this to this <tr> <th><?php echo $list['first_name'] ?></th> <th><?php echo $list['last_name'] ?></th> <th><?php echo $list['one'] ?></th> <th><?php echo $list['two'] ?></th> <th><?php echo $list['five'] ?></th> <th><?php echo $list['ten'] ?></th> <th><?php echo $list['fifteen'] ?></th> <th><?php echo $list['twenty'] ?></th> <th><?php echo $list['half'] ?></th> <th><?php echo $list['full'] ?></th> </tr> </tbody> </table>
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
access advice age amd avatar backup blue gene combo daniweb data data protection database dos dropdownlist economy encryption energy europe forensic forensics hardware help ibm ibm. news intel ibm it linux medicine memory microsoft module news open source openoffice pc privacy ps3 recession red hat russia security server storage sun supercomputer supercomputing technology trends web working
- Pulling Data from two tables (PHP)
- Help with query (PHP)
- ORA-01013: user requested cancel of current operation (C#)
- ORA-01013: user requested cancel of current operation (ASP.NET)
- I am working on an ASP.net 2.0 application written in C#, pulling data from an Oracle (Oracle)
- Need help passing database column value to a string variable. (ASP.NET)
- code optimization ... (C++)
- Inserting Data into Access Database (Java)
- ASP.NET Tutorial: Caching in ASP.NET (ASP.NET)
- Can this be done? (MS Access and FileMaker Pro)
Other Threads in the PHP Forum
- Previous Thread: How use the bcc field
- Next Thread: is there any way to submit a form to a number of pages at the same time?


Linear Mode