Jump to content


Photo

Blank output problem


  • Please log in to reply
4 replies to this topic

#1 master82

master82
  • Members
  • PipPipPip
  • Advanced Member
  • 182 posts

Posted 05 September 2006 - 11:27 AM

What is wrong with this code?

<?php
include("database.php");
$userstable = mysql_query("SELECT * FROM users WHERE userid = '1'");
if (!$userstable) {
   echo 'Could not run users query: ' . mysql_error();
   exit;
}
$user = mysql_fetch_row($userstable);

//testing
echo $user[userid];
echo $user[username];
?>


When I run it I donr get any errors, just a blank page ???

#2 zawadi

zawadi
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationChippenham UK

Posted 05 September 2006 - 11:36 AM

try this:

<?php
include("database.php");
$userstable = mysql_query("SELECT * FROM users WHERE userid = '1'");
if (!$userstable) {
  echo 'Could not run users query: ' . mysql_error();
  exit;
}
$user = mysql_fetch_row($userstable);

//testing
echo $user[0];
echo $user[1];
?>


you may need to edit the numbers to match the colum number.
Also RTFM http://uk.php.net/ma...l-fetch-row.php
That's the beauty of asymmetric warfare. You don't need a lot of money, or an army of people. You can do it from the comfort of your living room, with a beer in your hand.

#3 master82

master82
  • Members
  • PipPipPip
  • Advanced Member
  • 182 posts

Posted 05 September 2006 - 11:40 AM

That works great!

But is there a way I can assign the values using their fieldnames rather than a number?

eg

$user[username] (would show the username)

rather than

$user[1]

is it possible?

#4 Unknown User

Unknown User
  • Members
  • PipPip
  • Member
  • 16 posts

Posted 05 September 2006 - 12:03 PM

Err, i'm sure i do that.

Add

seesion_start();

at the top.

Then, if you want their username for example.

$_SESSION['username']



#5 zawadi

zawadi
  • Members
  • PipPip
  • Member
  • 25 posts
  • LocationChippenham UK

Posted 05 September 2006 - 12:06 PM

Description
array mysql_fetch_row ( resource result )

Returns a numerical array that corresponds to the fetched row and moves the internal data pointer ahead.


to use mysql_fetch_object

then use $user->username;
That's the beauty of asymmetric warfare. You don't need a lot of money, or an army of people. You can do it from the comfort of your living room, with a beer in your hand.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users