View previous topic :: View next topic |
Author |
Message |
midnite Guru


Joined: 09 Apr 2006 Posts: 451 Location: Hong Kong
|
Posted: Tue Jul 11, 2006 5:14 pm Post subject: [solved] php & mysql |
|
|
excuse me, why i can't use the following: Code: | <?php $abc = mysql_query('SELECT title FROM page');
echo mysql_result($abc, 2, 'title'); ?> | neither the following: Code: | <?php $abc = mysql_query('SELECT title FROM page');
echo mysql_result($abc, 2); ?> | both don't work -.-
would anyone kindly give me a hand ?
http://hk2.php.net/manual/en/function.mysql-result.php
* oh!! sorry for my providing too little.
the error is: Quote: | Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /labz/htdocs/andy-uc/base.php on line 45 |
and yes, i have connected and logged in well. Functions such as mysql_fetch_array(), mysql_query(), mysql_fetch_assoc() work well around it. Sadly itself won't. i suspect it's syntax problem @.@
Last edited by midnite on Tue Jul 11, 2006 6:01 pm; edited 2 times in total |
|
Back to top |
|
 |
mazaryk n00b


Joined: 03 Jul 2004 Posts: 62
|
Posted: Tue Jul 11, 2006 5:22 pm Post subject: |
|
|
Could be many reasons, you don't give enough info.
Did you connect to the database with mysql_connect() and select a db with mysql_select_db() ?
Do you receive any error message(s)?
Do the tables exists? Can you login through the mysql command line? _________________ http://www.mazaryk.com/ |
|
Back to top |
|
 |
basvanlola n00b


Joined: 10 Oct 2004 Posts: 52 Location: Eefde, The Netherlands
|
Posted: Tue Jul 11, 2006 5:47 pm Post subject: |
|
|
I would add some error checking:
Code: |
<?php
$abc = mysql_query ( "SELECT title FROM page" );
if ( $abc != FALSE ) {
echo ( mysql_result ( $abc, 2 ) );
} else {
die ( "whoops: " . mysql_error() );
}
?>
|
You should also add checks to calls to mysql_connect() and mysql_select_db() .
I always use 'error_reporting(E_ALL);' in my scripts when coding so I can see where I screwed up. Remember to remove this when going live... _________________ Athlon-XP 2000 @ 2083MHz
Asus A7V8X-X
1 GB DDR-333 ram
nVidia Geforce FX-5500
120 GB Maxtor 6Y120P0 |
|
Back to top |
|
 |
midnite Guru


Joined: 09 Apr 2006 Posts: 451 Location: Hong Kong
|
Posted: Tue Jul 11, 2006 6:00 pm Post subject: |
|
|
basvanlola wrote: | I would add some error checking:
Code: |
<?php
$abc = mysql_query ( "SELECT title FROM page" );
if ( $abc != FALSE ) {
echo ( mysql_result ( $abc, 2 ) );
} else {
die ( "whoops: " . mysql_error() );
}
?>
|
You should also add checks to calls to mysql_connect() and mysql_select_db() .
I always use 'error_reporting(E_ALL);' in my scripts when coding so I can see where I screwed up. Remember to remove this when going live... |
oh!! thanks very much!! you really GENIUS !!
i am such an idiot that having the line mysql_close($link); ahead.
Quote: | whoops: No database selected |
|
|
Back to top |
|
 |
basvanlola n00b


Joined: 10 Oct 2004 Posts: 52 Location: Eefde, The Netherlands
|
Posted: Tue Jul 11, 2006 6:36 pm Post subject: |
|
|
Quote: | Quote: | whoops: No database selected |
|
Glad I could help. _________________ Athlon-XP 2000 @ 2083MHz
Asus A7V8X-X
1 GB DDR-333 ram
nVidia Geforce FX-5500
120 GB Maxtor 6Y120P0 |
|
Back to top |
|
 |
|