Jump to content


Photo

mysql help...


  • Please log in to reply
7 replies to this topic

#1 somo

somo
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 09 July 2006 - 03:59 PM

I know this is simple but i just cant get it working.. how would you about return one value in a datbase?

$result = mysql_query( "SELECT R_RoomAvailiability FROM Room WHERE R_ID='$R_ID' " )

i need the value from this query can any one help?

cheers

#2 ShogunWarrior

ShogunWarrior
  • Members
  • PipPipPip
  • Advanced Member
  • 528 posts
  • LocationIreland

Posted 09 July 2006 - 04:05 PM

Ok, first I think R_ID is probably a number so you don't need quotes, e.g: $R_ID instead of '$R_ID'

To get the values do this:
$row = mysql_fetch_assoc($result);
$R_Room_Availability = $row['SELECT R_RoomAvailiability'];

<a href="http://www.daviddora...nmedia.com/">My New Site/Blog</a> | <a href="http://www.daviddora...m/check/">Check your page for broken links/images/scripts</a>

Zend Certified Engineer
Follow me on Twitter: http://twitter.com/davidd

#3 somo

somo
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 09 July 2006 - 04:19 PM

im gettin a parse errror


$result = mysql_query( "SELECT R_RoomAvailiability FROM Room WHERE R_ID=$R_ID " )
<b>$row = mysql_fetch_assoc($result);  <---error is here for some reason</b>
$R_RoomAvailability = $row['SELECT R_RoomAvailiability'];

Ok, first I think R_ID is probably a number so you don't need quotes, e.g: $R_ID instead of '$R_ID'

To get the values do this:

$row = mysql_fetch_assoc($result);
$R_Room_Availability = $row['SELECT R_RoomAvailiability'];



#4 Gast

Gast
  • Members
  • PipPipPip
  • Advanced Member
  • 131 posts
  • LocationSouth East England

Posted 09 July 2006 - 04:20 PM

Try this:

<?php
$result = mysql_query("SELECT R_RoomAvailiability FROM Room WHERE R_ID = ".$R_ID." LIMIT 1") or die(mysql_error());
$row = mysql_fetch_assoc($result);  //<---error is here for some reason
$R_RoomAvailability = $row['SELECT R_RoomAvailiability'];
echo $R_RoomAvailability;
?>

OS and Internet Specs:
Windows XP (with SP2), 1680x1050, PHP 4, MySQL 3, Internet Explorer 6 &7 /FireFox 2.0/Opera 9.2

Tutorials:
Simple Introduction to AJAX and XMLHttpRequest
Creating Live Data with AJAX Making a Google Suggest like application

#5 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 09 July 2006 - 04:24 PM

You forgot the terminating semi-colon on this line:
<?php $result = mysql_query( "SELECT R_RoomAvailiability FROM Room WHERE R_ID=$R_ID " ) ?>

Ken

#6 somo

somo
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 09 July 2006 - 04:32 PM

Another error lol

Undefined index: SELECT R_RoomAvailiability

$result = mysql_query("SELECT R_RoomAvailiability FROM Room WHERE R_ID = ".$R_ID." LIMIT 1") or die(mysql_error());
$row = mysql_fetch_assoc($result);
<b>$R_Room_Availability = $row['SELECT R_RoomAvailiability']; //<-- error here now :( </b>

Try this:

<?php
$result = mysql_query("SELECT R_RoomAvailiability FROM Room WHERE R_ID = ".$R_ID." LIMIT 1") or die(mysql_error());
$row = mysql_fetch_assoc($result);  //<---error is here for some reason</b>
$R_RoomAvailability = $row['SELECT R_RoomAvailiability'];
echo $R_RoomAvailability;
?>



#7 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 09 July 2006 - 04:34 PM

You only need to specify the field name as the index:
<?php $R_RoomAvailability = $row['R_RoomAvailiability']; ?>

Ken

#8 somo

somo
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 09 July 2006 - 04:37 PM

Thanks for that its working now cheers! :)


You only need to specify the field name as the index:

<?php $R_RoomAvailability = $row['R_RoomAvailiability']; ?>

Ken






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users