Page 1 of 1
simple db help for php row
Posted: Mon Aug 19, 2002 9:47 am
by vaska
sorry...i've been stuck with duties dealing with a php/mysql setup...but i have not knowledge of these things...well, not much...
what i need to do is very simple...
with a link such as
http://www.??????.com/webpage.php?id=2 or 3 or whatever...
i just need the page to return the correct row of information and insert it into the page...that's it...but i'm clueless...
i have connected to the database though...and can extract info from the db...but, only from the first record...i can't get other rows of information?
i've been searching all day...can anybody help?
thanks...jv
Posted: Mon Aug 19, 2002 11:48 am
by twigletmac
What does your code look like thus far?
Mac
Posted: Mon Aug 19, 2002 11:48 am
by Takuma
Code: Select all
$sql = SELECT * FROM yourTable WHERE id = ".$_GETїid]
Then....
Code: Select all
$temp = mysql_query($sql);
while($result = mysql_fetch_array($temp))
ї
echo $resultїCOLUMN NAME];
echo $resultїCOLUMN NAME2];
]
To access the diffrent column change the COLUMN NAME and COLUMN NAME2 etc.
Posted: Mon Aug 19, 2002 12:05 pm
by vaska
hi!
looks like this...sequence is acting as ID (i didn't set that up)...
thanks mucho for any input...jv
<?
mysql_connect("localhost"," "," ");
mysql_select_db("reviews");
$query = mysql_query("SELECT * FROM review where sequence='$sequence' " ) or die ("Unexpected error for MySQL database [1b]");
$row = mysql_fetch_array($query);
?>
Posted: Mon Aug 19, 2002 2:00 pm
by Takuma
???
yep
Posted: Tue Aug 20, 2002 3:05 am
by vaska
might look funny...but it's doing what i want it to do...but i know it's not correct...jv
Posted: Tue Aug 20, 2002 4:42 am
by mikeq
Nothing wrong with that just put in the WHILE part
while($row=mysql_fetch_array($query)){
print "My first column is ".$row[COLUMN_NAME_HERE];
...
}
On another point the die statement after your SQL is probably not much use unless you have completely screwed up the SQL syntax, which you haven't or the table gets deleted, so it will never be called. It is probably better to place it at the connect statement.
column name?
Posted: Tue Aug 20, 2002 9:15 am
by vaska
why would i want column information...
i want one record...one row of information...
maybe i explained it wrong...probably...
i know it's not the best...it's working...so far...
thanks...jv
Posted: Tue Aug 20, 2002 9:42 am
by conthox
If you print out all columns - you got one row!
Re: column name?
Posted: Wed Aug 21, 2002 6:00 am
by mikeq
vaska wrote:why would i want column information...
i want one record...one row of information...
maybe i explained it wrong...probably...
i know it's not the best...it's working...so far...
thanks...jv
The print "My first column is ".$row[COLUMN_NAME_HERE]; was an example, sorry did you want us to write the whole thing for you, give me a couple of weeks and wait by your email.