Page 1 of 1

A hint desparately needed...

Posted: Tue Sep 09, 2003 9:28 pm
by Maxaipa
I've been at this for a few months and just recently found a good grasp on the include() and require() functions, CSS layout, and the like. However, in trying to display a single row from a table I have become somewhat catatonic. I'm hoping that someone might be so kind as to give me a clue towards accomplishing this - as follows:

I have a 'search' page with a simple form - enter a number and post to another page called 'results'. The number that is entered on 'search' is unique and has nine other fields in the row. What I would like to see is 1 row with all fields included, but for the life of me, I see nothing. The db connect statements don't return any errors and I'm quite positive that it's not the issue.

Anyone have a quick sample of how I would retrieve the query results in the 'results' page - I've tried so many different things, I don't even remember what I've done. I apologize if this is too vague - 6 hours at the puter has made me somewhat "mushy" in the head.

Even the slightest hint may be most helpful.

Undying thanks and appreciation!!

Posted: Tue Sep 09, 2003 10:24 pm
by JAM
If I understood correctly; You need to rewrite my example, but basicly...

Code: Select all

SELECT * FROM table LIMIT $search,1
Select everything from table, starting at line $search. The last 1 means 'one row' from $start.

Posted: Tue Sep 09, 2003 10:43 pm
by McGruff
It's usually better not to just post a script - better to help someone work it out for themselves. But since it sounds like you've spent a lot of time on this already here's a sample:

Code: Select all

<?php

// defines a string - the db query
// replace col1 etc with your own column and table names
$mysql = "SELECT col1, col2, col3 FROM table WHERE id='$id'";

// creates a result resource - a mysterious entity a bit like an array only it's not
// also some commonly used error handling (the or step)
$query = mysql_query(mysql) or die('oh bugger' . mysql_error() . '<br />');

// now this IS an array - fetches a row from the result resource (just one here) as an array with numerical and associative keys (try a print_r() on it)
$result = mysql_fetch_array($query);

// assign the keys 
$var1 = $result['var1'];
$var2 = $result['var2'];
$var3 = $result['var3'];
// etc..
?>

Posted: Wed Sep 10, 2003 2:08 pm
by Maxaipa
Thanks to both of you for your time!!! With your guidance (and a liitle sleep) I managed to sort it out - I'm now seeing what I expected to see and learned alot in the process.

Cheers mates!!!

McGruff... I miss Glasgow, how's the weather?