Forum Moderators: coopster

Message Too Old, No Replies

Displaying Different Rows from database

         

h3ktlk

6:41 pm on May 21, 2007 (gmt 0)

10+ Year Member



Heres my issue,

i have say a 40 row database maybe 10 columns across..

i need to grab one column entry from say row 10 an display at point X on a website.. now at point T i might need to display another column entry on row 32...

There a way to echo for a specific row? other then looping? if i loop can i control where they display and not just list?

Thanks!

dreamcatcher

7:06 pm on May 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi h3ktlk, welcome to Webmaster World. :)

Looks like you need a WHERE clause:

$query = mysql_query("SELECT column FROM table WHERE id = 'id_number' LIMIT 1") or die(mysql_error());
$row = mysql_fetch_object($query);

echo $row->column;

dc

eelixduppy

7:31 pm on May 21, 2007 (gmt 0)



You could also use mysql_result [php.net] to get specific rows from a mysql result, but it depends on what you are doing to decide how useful this would be to you :)

h3ktlk

11:07 am on May 22, 2007 (gmt 0)

10+ Year Member



ok heres what i have i just get blank screen now.. sorry im still learning this stuff.. and thanks for the welcome!

mysql_select_db($database_sum_enrich, $sum_enrich);
$query_EventSession1K = "SELECT * FROM eventssession1 WHERE GradeK = 'yes'";
$query = "SELECT column FROM table WHERE id ='id_number' LIMIT 1") or die(mysql_error()));
$EventSession1K = mysql_query($query_EventSession1K, $sum_enrich) or die(mysql_error());
$row_EventSession1K = mysql_fetch_assoc($EventSession1K);
$totalRows_EventSession1K = mysql_num_rows($EventSession1K);
$row = mysql_fetch_object($query);

then echos

<?php
echo $row->2;
?>

? is that what you meant are my querys conflicting?

Thanks!

delboy1978uk

12:32 pm on May 22, 2007 (gmt 0)

10+ Year Member



i think what he meant was to tailor the query in the format he suggested, not literally

$query = "SELECT column FROM table WHERE id ='id_number' LIMIT 1") or die(mysql_error()));

where he says column key in whatever column name you want to see instead of * in your original query

where he says table i take it that would mean eventsession1

where he says id number he means whatever the name of your tables primary key is.

so instead of:

$query_EventSession1K = "SELECT * FROM eventssession1 WHERE GradeK = 'yes'";

try something along the lines of
(bits you need to alter in square brackets)
:

$query_EventSession1K = "SELECT [name_of_column_to_select] FROM eventssession1 WHERE GradeK = 'yes' AND [primary_key_name] = [primary_key_number]";

if you have the key number as $variable then you could type in like:

$query_EventSession1K = "SELECT [name_of_column_to_select] FROM eventssession1 WHERE GradeK = 'yes' AND [primary_key_name] = ".$variable;

hope that helps you some

h3ktlk

1:39 pm on May 22, 2007 (gmt 0)

10+ Year Member



Now my problem is its not pulling any data..

mysql_select_db($database_sum_enrich, $sum_enrich);
$query_EventSession1K = mysql_query("SELECT EventName FROM eventssession1 WHERE GradeK = 'yes' AND EventID = 1 LIMIT 1") or die(mysql_error());
$row_EventSession1K = mysql_fetch_object($query_EventSession1K);
$totalRows_EventSession1K = mysql_num_rows($query_EventSession1K);

delboy1978uk

4:12 pm on May 22, 2007 (gmt 0)

10+ Year Member



in that case record one probably isn't set to yes