Jump to content


Photo

turning a MySQL resource into a number or string?



  • Please log in to reply
2 replies to this topic

#1 dannerz

dannerz

    Member

  • Members
  • PipPip
  • 29 posts

Posted 02 March 2014 - 11:57 AM

echo "you bought 1 archer";
$data = mysql_query("SELECT Vals FROM vals2 WHERE ValsN = 'archers'");
if ($data == false) exit("This has failed");
$msg = mysql_fetch_assoc($data);
echo "<br />";
echo $msg;//this just says that it is an array
echo "<br />";
echo $data;
echo "<br />";
$msg2 = mysql_num_fields($data);
echo $msg2;
echo "<br />";
$msg3 = mysql_fetch_row($data);//this is not shown for some reason
echo $msg3;

This is the code.

 

I'd like to get a number out of the db, and convert the resource into just a number value or string, then alter the number in PHP (i know how to do that part) then put the number back into the db (I think I can do that also)

I just don't know how to convert a resource ("$data") into a variable to use in the PHP code.

 

Hopefully you know what I mean.

 

(the output of the above code is)

Shop choice method.
you bought 1 archer
Array
Resource id #4
1


Edited by dannerz, 02 March 2014 - 12:00 PM.


#2 Barand

Barand

    Sen . ( ile || sei )

  • Gurus
  • 14,647 posts
  • LocationCheshire, UK

Posted 02 March 2014 - 12:39 PM   Best Answer

have a look at the example in the manual http://uk1.php.net/m...fetch-assoc.php


moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts
|baaSelect| generate js and php code for dynamic linked dropdowns

 


#3 dannerz

dannerz

    Member

  • Members
  • PipPip
  • 29 posts

Posted 02 March 2014 - 12:53 PM

I'll start copy pasting and editing (thanks)


Edited by dannerz, 02 March 2014 - 12:53 PM.





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com