User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 397,716 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,539 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: 695 | Replies: 31 | Solved
Reply
Join Date: Apr 2008
Location: Lahore, Pakistan
Posts: 36
Reputation: mustafaneguib is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
mustafaneguib mustafaneguib is offline Offline
Light Poster

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

  #11  
Jul 25th, 2008
you can use mysql_fetch_assoc in the following.
this is wat i know but i may be wrong.

  1. while( $list=mysql_fetch_assoc($result))
  2. {
  3. foreach($list as $val)
  4. {
  5. echo $val;
  6. }
  7. echo "<br />";
  8. }
  9.  
Reply With Quote  
Join Date: Mar 2008
Posts: 85
Reputation: justinmyoung is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
justinmyoung justinmyoung is offline Offline
Junior Poster in Training

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

  #12  
Jul 25th, 2008
I added the extra die functions, and I tried to change $list=mysql_fetch_array($result); to this
while( $list=mysql_fetch_assoc($result))
{
 foreach($list as $val)
{
echo $val;
}
echo "<br />";
}
but it's not working.

Instead, I'm getting a strange error that says: Unknown column 'Justin' in 'where clause'

Justin is the test name I have in the database. I'm stumped.

So what I have now looks like this:

[icode] <?php
// Include connection to your database
$con = mysql_connect("localhost","root","rilke123");
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>
[/code]

Thanks again!
Last edited by justinmyoung : Jul 25th, 2008 at 10:17 am. Reason: added code
Reply With Quote  
Join Date: Jun 2008
Location: Phoenix, AZ
Posts: 592
Reputation: R0bb0b is on a distinguished road 
Rep Power: 2
Solved Threads: 52
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Posting Pro

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

  #13  
Jul 25th, 2008
echo your query and post it.
“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
Reply With Quote  
Join Date: Mar 2008
Posts: 85
Reputation: justinmyoung is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
justinmyoung justinmyoung is offline Offline
Junior Poster in Training

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

  #14  
Jul 25th, 2008
not sure how to echo my query. as simple as it may be...

thanks again!
Reply With Quote  
Join Date: Jun 2008
Location: Phoenix, AZ
Posts: 592
Reputation: R0bb0b is on a distinguished road 
Rep Power: 2
Solved Threads: 52
R0bb0b's Avatar
R0bb0b R0bb0b is offline Offline
Posting Pro

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

  #15  
Jul 25th, 2008
right under this line
$query = "SELECT * FROM runners WHERE id = '$name'";


put
echo $query;
run it, copy the results, and post it.
Last edited by R0bb0b : Jul 25th, 2008 at 6:46 pm.
“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
Reply With Quote  
Join Date: Mar 2008
Posts: 85
Reputation: justinmyoung is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
justinmyoung justinmyoung is offline Offline
Junior Poster in Training

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

  #16  
Jul 25th, 2008
This is what I got:

SELECT * FROM runners WHERE id =JustinUnknown column 'Justin' in 'where clause'

I only have 1 column of data in the database. Justin is the first name.
Reply With Quote  
Join Date: Mar 2008
Posts: 85
Reputation: justinmyoung is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
justinmyoung justinmyoung is offline Offline
Junior Poster in Training

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

  #17  
Jul 25th, 2008
it seems like it has something to do with the 'while' loop not wrapping around the code...?
Reply With Quote  
Join Date: Apr 2008
Location: Lahore, Pakistan
Posts: 36
Reputation: mustafaneguib is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
mustafaneguib mustafaneguib is offline Offline
Light Poster

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

  #18  
Jul 25th, 2008
can u copy and past ur table structure here. i think there is a problem in there.

the id which you are using in
where id=$name

is id an integer field or a string field? because id is usually used as an integer and is a unique value.
Reply With Quote  
Join Date: Mar 2008
Posts: 85
Reputation: justinmyoung is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
justinmyoung justinmyoung is offline Offline
Junior Poster in Training

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

  #19  
Jul 25th, 2008
Here's the table structure:

CREATE TABLE IF NOT EXISTS `runners` (
  `id` mediumint(50) unsigned NOT NULL auto_increment,
  `first_name` varchar(50) NOT NULL,
  `last_name` smallint(50) NOT NULL,
  `one` smallint(50) NOT NULL,
  `two` smallint(50) NOT NULL,
  `five` smallint(50) NOT NULL,
  `ten` smallint(50) NOT NULL,
  `fifteen` smallint(50) NOT NULL,
  `twenty` smallint(50) NOT NULL,
  `half` smallint(50) NOT NULL,
  `full` smallint(50) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

--
-- Dumping data for table `runners`
--

INSERT INTO `runners` (`id`, `first_name`, `last_name`, `one`, `two`, `five`, `ten`, `fifteen`, `twenty`, `half`, `full`) VALUES
(1, 'Justin', 0, 400, 800, 1300, 2700, 4500, 5800, 6000, 20000);
Last edited by Tekmaven : 34 Days Ago at 3:42 am. Reason: Code Tags
Reply With Quote  
Join Date: Apr 2008
Location: Lahore, Pakistan
Posts: 36
Reputation: mustafaneguib is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
mustafaneguib mustafaneguib is offline Offline
Light Poster

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

  #20  
Jul 25th, 2008
ive found ur mistake. ur using
the following,
  1. $name = $_POST['first'];
  2. $query = "SELECT * FROM runners WHERE id =".$name;

do this,
  1. $name = $_POST['first'];
  2. $query = "SELECT * FROM runners WHERE first_name =".$name;

u are using the wrong field. u are comparing an int field with string and ur are comparing the id field with the name.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 2:05 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC