| | |
please help with pulling data from database...
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Mar 2008
Posts: 129
Reputation:
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
Posts: 75
Reputation:
Solved Threads: 3
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 7:50 pm.
•
•
Join Date: Mar 2008
Posts: 129
Reputation:
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: 129
Reputation:
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!
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;
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
•
•
Join Date: Mar 2008
Posts: 129
Reputation:
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!
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 1: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
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
•
•
Join Date: Apr 2008
Posts: 75
Reputation:
Solved Threads: 3
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>
![]() |
Similar Threads
- 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?
| Thread Tools | Search this Thread |
.htaccess alerts apache api archive array autocomplete beginner binary broken cakephp checkbox class cms code convert cron curl database dataentry date display duplicates dynamic echo email emptydisplayvalue error execute explodefunction file files firstoptioninphpdroplist folder form forms function functions google hack href htaccess html htmlspecialchars image include insert ip javasciptvalidation javascript joomla keywords limit link login mail matching menu methods mlm multiple mysql network object oop paypal pdf php problem query radio random recursion recursive redirect remote script search securephp server sessions shot sms source space sql subscription syntax system table tutorial tutorials update upload url validator variable video web youtube






