please help with pulling data from database...

Thread Solved

Join Date: Mar 2008
Posts: 129
Reputation: justinmyoung is an unknown quantity at this point 
Solved Threads: 0
justinmyoung justinmyoung is offline Offline
Junior Poster

please help with pulling data from database...

 
0
  #1
Jul 24th, 2008
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: <?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>
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 75
Reputation: mustafaneguib is an unknown quantity at this point 
Solved Threads: 3
mustafaneguib mustafaneguib is offline Offline
Junior Poster in Training

Re: please help with pulling data from database...

 
0
  #2
Jul 24th, 2008
try to use
  1. <?php while ($list = mysql_fetch_array($result)) {?>

instead of,

  1. <?php while ($list = mysql_fetch_assoc($result)) {?>
Last edited by mustafaneguib; Jul 24th, 2008 at 7:50 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 129
Reputation: justinmyoung is an unknown quantity at this point 
Solved Threads: 0
justinmyoung justinmyoung is offline Offline
Junior Poster

Re: please help with pulling data from database...

 
0
  #3
Jul 24th, 2008
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:

<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!
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 129
Reputation: justinmyoung is an unknown quantity at this point 
Solved Threads: 0
justinmyoung justinmyoung is offline Offline
Junior Poster

Re: please help with pulling data from database...

 
0
  #4
Jul 25th, 2008
Well I got it to come up with no errors, but it's not pulling the data:


<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!
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 171
Reputation: praveen_dusari is an unknown quantity at this point 
Solved Threads: 21
praveen_dusari's Avatar
praveen_dusari praveen_dusari is offline Offline
Junior Poster

Re: please help with pulling data from database...

 
0
  #5
Jul 25th, 2008
hi,
echo your sql query. you didn`t put die() it will display error if database is selected or not
Failure is success if we learn from it
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,072
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: please help with pulling data from database...

 
0
  #6
Jul 25th, 2008
change this :
  1. $query = "SELECT * FROM runners WHERE id = '$name'";

To:
  1. $query = "SELECT * FROM runners WHERE id =".$name;
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 129
Reputation: justinmyoung is an unknown quantity at this point 
Solved Threads: 0
justinmyoung justinmyoung is offline Offline
Junior Poster

Re: please help with pulling data from database...

 
0
  #7
Jul 25th, 2008
1. Looks like I'm connecting fine. I added the die function.

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!
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,072
Reputation: Shanti Chepuru is on a distinguished road 
Solved Threads: 98
Shanti Chepuru's Avatar
Shanti Chepuru Shanti Chepuru is offline Offline
Veteran Poster

Re: please help with pulling data from database...

 
0
  #8
Jul 25th, 2008
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...
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 849
Reputation: R0bb0b is on a distinguished road 
Solved Threads: 67
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Practically a Posting Shark

Re: please help with pulling data from database...

 
0
  #9
Jul 25th, 2008
put in more die functions.

  1. <?php
  2. // Include connection to your database
  3. $con = mysql_connect("localhost","root","") or die(mysql_error());;
  4. mysql_select_db("RUNNERS", $con) or die(mysql_error());
  5.  
  6. $name = $_POST['first'];
  7. $query = "SELECT * FROM runners WHERE id =".$name;
  8. $result = mysql_query($query) or die(mysql_error());?>
  9.  
  10. <table class="sortable">
  11. <!-- Table Header -->
  12. <thead>
  13. <tr>
  14. <th>ID #</th>
  15. <th>First Name</th>
  16. <th>Last Name</th>
  17. <th>1 Mile</th>
  18. <th>2 Mile</th>
  19. <th>5k</th>
  20. <th>8k</th>
  21. <th>10k</th>
  22. <th>20k</th>
  23. <th>13.1</th>
  24. <th>26.2</th>
  25. </tr>
  26. </thead>
  27.  
  28. <!-- Table body-->
  29. <tbody>
  30. <?php while ($list = mysql_fetch_assoc($result)) ?>
  31. <tr>
  32. <th><?php echo $list['first_name'] ?></th>
  33. <th><?php echo $list['last_name'] ?></th>
  34. <th><?php echo $list['one'] ?></th>
  35. <th><?php echo $list['two'] ?></th>
  36. <th><?php echo $list['five'] ?></th>
  37. <th><?php echo $list['ten'] ?></th>
  38. <th><?php echo $list['fifteen'] ?></th>
  39. <th><?php echo $list['twenty'] ?></th>
  40. <th><?php echo $list['half'] ?></th>
  41. <th><?php echo $list['full'] ?></th>
  42. </tr>
  43. </tbody>
  44.  
  45.  
  46. </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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 75
Reputation: mustafaneguib is an unknown quantity at this point 
Solved Threads: 3
mustafaneguib mustafaneguib is offline Offline
Junior Poster in Training

Re: please help with pulling data from database...

 
0
  #10
Jul 25th, 2008
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,

  1. $list=mysql_fetch_array($result);
instead of it because your problem lies in this line.


  1.  
  2. <!-- Table body-->
  3. <tbody>
  4. <?php $list=mysql_fetch_array($result); ?> //change this to this
  5. <tr>
  6. <th><?php echo $list['first_name'] ?></th>
  7. <th><?php echo $list['last_name'] ?></th>
  8. <th><?php echo $list['one'] ?></th>
  9. <th><?php echo $list['two'] ?></th>
  10. <th><?php echo $list['five'] ?></th>
  11. <th><?php echo $list['ten'] ?></th>
  12. <th><?php echo $list['fifteen'] ?></th>
  13. <th><?php echo $list['twenty'] ?></th>
  14. <th><?php echo $list['half'] ?></th>
  15. <th><?php echo $list['full'] ?></th>
  16. </tr>
  17. </tbody>
  18.  
  19.  
  20. </table>
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC