Forum Moderators: coopster

Message Too Old, No Replies

how to assign data in a table field to a variable

         

mylungsarempty

6:16 pm on Jan 9, 2004 (gmt 0)

10+ Year Member



what exactly do i do to only retrieve information from a table and assign it to a variable? I don't want to manipulate the data in any way, just display it on the page.

kknusa

6:26 pm on Jan 9, 2004 (gmt 0)

10+ Year Member



$link= mysql_connect("DBHost","DBUser","DBPass");
$result=mysql("$DBName","SELECT * Table ");
while ($row = mysql_fetch_row($result)) {
$var=$row[0];
}

mylungsarempty

6:49 pm on Jan 9, 2004 (gmt 0)

10+ Year Member



$result=mysql("SELECT FROM musicians WHERE username = '$username' ");

while ($row = mysql_fetch_row($result)) {

$var=$row[0];

}

this gives me an error saying wrong parameter count for sql. what did i do wrong there?

brotherhood of LAN

6:54 pm on Jan 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



>>>>$result = mysql

Change that to $result = mysql_query and give that a run through.

mylungsarempty

7:09 pm on Jan 9, 2004 (gmt 0)

10+ Year Member



thankyou. that eliminated my first error... now i have this one:

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource

$result = mysql_query("SELECT FROM musicians WHERE username = '$username' ");

while ($row = mysql_fetch_row($result)) {

$var=$row[0];

}

That's the code... do you see a syntactical error?

DrDoc

7:15 pm on Jan 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Did you do mysql_connect first?

mylungsarempty

7:17 pm on Jan 9, 2004 (gmt 0)

10+ Year Member



yes, the actual connection to the database is not an issue.

Birdman

7:19 pm on Jan 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try adding an asterisk(*), or the actual fields you want to retrieve, just after SELECT.

SELECT * FROM...

SELECT id,name,etc FROM...

DrDoc

7:27 pm on Jan 9, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well spotted Birdman ;)

mylungsarempty

8:46 pm on Jan 9, 2004 (gmt 0)

10+ Year Member



well just for fun, here's the finished code that i finally got working...

<?php

mysql_select_db($db, $con);

$select = "SELECT DISTINCT ID, username, name, email, city, state, zip, nation";
$from = " FROM musicians";
$where = " WHERE '$username'=username";

$results = @mysql_query($select . $from . $where);
if (!$results) {
die('<p>error retrieving musicians<br>' . 'Error: ' . mysql_error() . '</p>');
}

while ($result = mysql_fetch_array($results)) {
$id = $result['ID'];
$musician = htmlspecialchars($result['username']);
$name = $result['name'];
$email = $result['email'];
$city = $result['city'];
$state = $result['state'];
$zip = $result['zip'];
$nation = $result['nation'];
}

?>

<FORM>

<B>Username:</B><BR>
&nbsp;&nbsp;&nbsp;&nbsp;<U><?php echo("$username");?></U>

Thanks.