Page 1 of 2
help
Posted: Sun May 11, 2003 1:36 pm
by Lonewolf
im trying to connect i got this script
<?php
$db = mysql_connect("localhost","root","pass");
mysql_select_db("mybuddy",$db);
//replace the above values with your actual database values
$sql_result = mysql_query("SELECT joke FROM jokes WHERE joke_no=1", $db);
$rs = mysql_fetch_row($sql_result);
echo $rs[0];
?>
says error on line 6 $rs = mysql_fetch_row($sql_result); is on line 6, anyone know whats wrong
Posted: Sun May 11, 2003 1:55 pm
by volka
//replace the above values with your actual database values
Did you do that?
same script, maybe with more error/warning-output
Code: Select all
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('mysql.trace_mode', TRUE);
$db = mysql_connect("localhost","root","pass");
mysql_select_db("mybuddy",$db);
//replace the above values with your actual database values
$sql_result = mysql_query("SELECT joke FROM jokes WHERE joke_no=1", $db);
$rs = mysql_fetch_row($sql_result);
echo $rs[0];
?>
Posted: Sun May 11, 2003 3:02 pm
by Lonewolf
yes but u think im gonna put my info there
Posted: Sun May 11, 2003 3:04 pm
by Lonewolf
SELECT joketable right? FROM jokestable right? WHERE joke_noa column?=1What row number?", $db);
am i right.
Posted: Sun May 11, 2003 3:58 pm
by AVATAr
SELECT column1, colum2 from table WHERE column1 = valuecolumn1
Example, a table called jokes:
Columns of that table: id, name, text
if i want the name and the text (both columns) of the joke number 2 (the id)
SELECT name, text from jokes WHERE id=2
Posted: Sun May 11, 2003 4:17 pm
by Lonewolf
how do i get the results of a table into a variable to i can put it in a table on a webpage
Posted: Sun May 11, 2003 4:21 pm
by Lonewolf
i get this errorWarning: Supplied argument is not a valid MySQL result resource in /customer/renhome/darknephthys/public_html/TMP70h2leqrcc.php on line 5
Warning: Supplied argument is not a valid MySQL result resource in /customer/renhome/darknephthys/public_html/TMP70h2leqrcc.php on line 6
Warning: Supplied argument is not a valid MySQL result resource in /customer/renhome/darknephthys/public_html/TMP70h2leqrcc.php on line 7
Warning: Supplied argument is not a valid MySQL result resource in /customer/renhome/darknephthys/public_html/TMP70h2leqrcc.php on line 8
Warning: Supplied argument is not a valid MySQL result resource in /customer/renhome/darknephthys/public_html/TMP70h2leqrcc.php on line 9
Warning: Supplied argument is not a valid MySQL result resource in /customer/renhome/darknephthys/public_html/TMP70h2leqrcc.php on line 10
Warning: Supplied argument is not a valid MySQL result resource in /customer/renhome/darknephthys/public_html/TMP70h2leqrcc.php on line 11
extra:
from this code
<?PHP
$dbconn = mysql_connect("localhost", "secret", "secret");
$result = mysql_select_db("secret", $dbconn);
$sql = "SELECT memb_username, memb_first , memb_email , memb_pass , memb_last ,memb_extra,memb_id FROM ss_users WHERE memb_country =0";
$first=mysql_result($result,$i,"memb_username ");
$last=mysql_result($result,$i,"memb_last");
$id=mysql_result($result,$i,"memb_id ");
$country=mysql_result($result,$i,"memb_country ");
$first=mysql_result($result,$i," memb_first ");
$email=mysql_result($result,$i,"memb_email ");
$extra=mysql_result($result,$i,"memb_extra ");
echo "<b>$first $last</b><br>extra:$extra<br>";
?>
whats wrong with it
Posted: Sun May 11, 2003 4:39 pm
by volka
before you can fetch results you have to send the query to mysql
http://php.net/mysql_query
Posted: Sun May 11, 2003 4:50 pm
by Lonewolf
ok added one got this error Warning: memb_username not found in MySQL result index 2 in /customer/renhome/darknephthys/public_html/TMP80uzpeqsni.php on line 7
Warning: memb_last not found in MySQL result index 2 in /customer/renhome/darknephthys/public_html/TMP80uzpeqsni.php on line 8
Warning: memb_id not found in MySQL result index 2 in /customer/renhome/darknephthys/public_html/TMP80uzpeqsni.php on line 9
Warning: memb_country not found in MySQL result index 2 in /customer/renhome/darknephthys/public_html/TMP80uzpeqsni.php on line 10
Warning: memb_first not found in MySQL result index 2 in /customer/renhome/darknephthys/public_html/TMP80uzpeqsni.php on line 11
Warning: memb_email not found in MySQL result index 2 in /customer/renhome/darknephthys/public_html/TMP80uzpeqsni.php on line 12
Warning: memb_extra not found in MySQL result index 2 in /customer/renhome/darknephthys/public_html/TMP80uzpeqsni.php on line 13
extra:
<?PHP
$dbconn = mysql_connect("localhost", "", "");
$result = mysql_select_db("", $dbconn);
$result = mysql_query("SELECT memb_first FROM ss_users")
or die("Invalid query: " . mysql_error());
$sql = "SELECT memb_username, memb_first , memb_email , memb_pass , memb_last ,memb_extra,memb_id FROM ss_users WHERE memb_country =0";
$first=mysql_result($result,$i,"memb_username ");
$last=mysql_result($result,$i,"memb_last");
$id=mysql_result($result,$i,"memb_id ");
$country=mysql_result($result,$i,"memb_country ");
$first=mysql_result($result,$i," memb_first ");
$email=mysql_result($result,$i,"memb_email ");
$extra=mysql_result($result,$i,"memb_extra ");
echo "<b>$first $last</b><br>extra:$extra<br>";
?>
Posted: Sun May 11, 2003 5:03 pm
by volka
$result = mysql_query("SELECT memb_first FROM ss_users")
the result contains only the values of the field memb_first for each entry in ss_users.
$sql = "SELECT memb_username, memb_first , memb_email , memb_pass , memb_last ,memb_extra,memb_id FROM ss_users WHERE memb_country =0";
if you want the result of this query you have to send
this query to mysql via mysql_query.
Posted: Sun May 11, 2003 8:08 pm
by Lonewolf
how
Posted: Sun May 11, 2003 8:17 pm
by volka
Code: Select all
<?php
// connecting to mysql-server
$dbconn = mysql_connect("localhost", "", "") or die(mysql_error());
// selecting database for that ($dbconn) mysql-connection
$result = mysql_select_db("", $dbconn) or die(mysql_error());
// querying something; result is identified by $result
$result = mysql_query("SELECT memb_first FROM ss_users", $dbconn) or die("Invalid query: " . mysql_error());
// nothing is done with this result....
// build another query-string
$sql = "SELECT memb_username, memb_first , memb_email , memb_pass , memb_last ,memb_extra,memb_id FROM ss_users WHERE memb_country=0";
// pass that new query to mysql (using the mysql-connection $dbconn)
$result = mysql_query($sql, $dbconn) or die("Invalid query: " . mysql_error());
// have to set $i....
// fetch some field-values of a record from the resultset
$first=mysql_result($result,$i,"memb_username ");
$last=mysql_result($result,$i,"memb_last");
$id=mysql_result($result,$i,"memb_id ");
$country=mysql_result($result,$i,"memb_country ");
$first=mysql_result($result,$i," memb_first ");
$email=mysql_result($result,$i,"memb_email ");
$extra=mysql_result($result,$i,"memb_extra ");
echo "<b>$first $last</b><br>extra:$extra<br>";
?>
Posted: Sun May 11, 2003 8:32 pm
by Lonewolf
did that got this Warning: memb_username not found in MySQL result index 3 in /customer/renhome/darknephthys/public_html/TMP5bcy6er2yf.php on line 19
Warning: memb_id not found in MySQL result index 3 in /customer/renhome/darknephthys/public_html/TMP5bcy6er2yf.php on line 21
Warning: memb_country not found in MySQL result index 3 in /customer/renhome/darknephthys/public_html/TMP5bcy6er2yf.php on line 22
Warning: memb_first not found in MySQL result index 3 in /customer/renhome/darknephthys/public_html/TMP5bcy6er2yf.php on line 23
Warning: memb_email not found in MySQL result index 3 in /customer/renhome/darknephthys/public_html/TMP5bcy6er2yf.php on line 24
Warning: memb_extra not found in MySQL result index 3 in /customer/renhome/darknephthys/public_html/TMP5bcy6er2yf.php on line 25
Bass
extra:
Posted: Sun May 11, 2003 8:41 pm
by volka
the value of $i is 3?
Maybe there not three records matching the where-clause.
you might try
Code: Select all
// fetch some field-values of a record from the resultset
$row = mysql_fetch_array($result) or die('no records match the conditions');
$first=$row['memb_username'];
$last=$row['memb_last'];
$id=$row['memb_id'];
$country=$row['memb_country'];
$first=$row['memb_first'];
$email=$row['memb_email'];
$extra=$row['memb_extra'];
echo "<b>$first $last</b><br>extra:$extra<br>";
to fetch the first record's values.
Also note, that there are some spaces in the fieldnames you pass to mysql_result, "memb_username " != "memb_username"
Posted: Sun May 11, 2003 8:49 pm
by Lonewolf
ok sweet it works thanks man