Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

Getting data from a single row...

Codes here !

Moderators: macek, egami, gesf

Getting data from a single row...

Postby daMax » Thu Jul 10, 2003 3:11 am

Hmmzz...I'm kinda new to PHP and the coding for it...but watching the code from others I felt this code should work:

Code: Select all
include('inloggegevens.php');
$tb_aanmeldingen="aanmeldingen";
$tb_dagspelspelers="dagspel_spelers";
$tb_dagspeltrekkingen="dagspel_trekkingen";
$tb_dagspelwinnaars="dagspel_winnaars";

$result = mysql_query("SELECT userid FROM $tb_aanmeldingen WHERE mobiel='0648938052'", $link )
  or die ("- query error 4! -");

if (mysql_num_rows($result) == 1) 
{
   extract ( mysql_fetch_row ($result) );
   $spelerid = $result[0];
   $datum = date("Y-m-d");
   $tijd = date("H:m:s");
}


However, if I try to read out "$spelerid" there's no value in it..why? What am I doing wrong? There can only be 1 row in this query...I don't get it...

Thanks,
Max.
daMax
New php-forum User
New php-forum User
 
Posts: 4
Joined: Tue Jul 08, 2003 1:43 am
Location: Den Bosch, the Netherlands

Postby Joel » Thu Jul 10, 2003 3:33 am

Your problem lies in your mysql query. I haven't used the extract function before, I usually use

$data = mysql_fetch_array($result);

But anyway, you have a "WHERE mobiel='0648938052'" but you have not selected this field. This is what you need to have.
Code: Select all
SELECT userid, mobiel FROM table WHERE mobiel='0648938052'

Then if you used mysql_fetch array you can print the user id for that mobiel (do you mean mobile?) like this
Code: Select all
echo $data["userid"];
Joel
New php-forum User
New php-forum User
 
Posts: 193
Joined: Sat Mar 29, 2003 11:57 pm
Location: Auckland, New Zealand

Postby daMax » Thu Jul 10, 2003 4:26 am

Thanks for your reply Joel,

It was in such a way helpful that I decided to take a new look at the way I was retrieving my data. However it wasn't the query that was the problem, all I needed to do was:

Code: Select all
$result = mysql_query("SELECT userid FROM $tb_aanmeldingen WHERE mobiel='0648938052'", $link )
  or die ("- query error 4! -");

if (mysql_num_rows($result) == 1) 
{
   extract ( mysql_fetch_row ($result) );
   $spelerid = $userid;
   $datum = date("Y-m-d");
   $tijd = date("H:m:s");
}


And that DID work.. :)
daMax
New php-forum User
New php-forum User
 
Posts: 4
Joined: Tue Jul 08, 2003 1:43 am
Location: Den Bosch, the Netherlands


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron