A hint desparately needed...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Maxaipa
Forum Newbie
Posts: 17
Joined: Sat May 10, 2003 6:08 pm

A hint desparately needed...

Post 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!!
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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..
?>
Last edited by McGruff on Wed Aug 10, 2005 7:22 pm, edited 1 time in total.
Maxaipa
Forum Newbie
Posts: 17
Joined: Sat May 10, 2003 6:08 pm

Post 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?
Post Reply