Page 1 of 1

Doesnt response on "if" statement?

Posted: Wed Aug 23, 2006 4:09 am
by jmansa
I'm trying to make my page show an "iframe" if certain parameters is ok, but it doesnt seem to work. Can somebody please guide me in the right direction?

1'st part.

Code: Select all

<?php

if (($_GET['uid']) && (is_numeric($_GET['uid']))) {
$userid = $_GET['uid'];

$dbhost = 'myhost';
$dbuser = 'myusername';
$dbpass = 'mypassword';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                    ("Error connecting to mysql: " . mysql_error());

$dbname = 'mydatabase';
mysql_select_db($dbname);

//var_dump($uid);
 
$query="SELECT * FROM users WHERE uid='".$uid."'"; 
$result=mysql_query($query) or die("Unable to find requested user");
$currUser = mysql_fetch_array($result);

?>
The call

Code: Select all

<?php if($currUser['uid']['3d']=='no') { echo '<iframe src= "/player/' . $currUser['uid'] . '.html" width="510" height="345" frameborder="0" scrolling="no"></iframe>';} ?>
The end

Code: Select all

<?php
} else {
echo "No user specified";
}
?>
Hope somebody can help!!!

Posted: Wed Aug 23, 2006 4:32 am
by jamiel
Underneath $currUser = mysql_fetch_array($result); add var_dump($currUser); . Rerun the script and show us the output of $currUser.

Posted: Wed Aug 23, 2006 4:34 am
by onion2k
$currUser['uid']['3d'] is wrong. Without seeing your database table schema I can only guess, but I reckon you want: $currUser['3d']

Posted: Wed Aug 23, 2006 4:36 am
by GM
I think that your $currUser['uid'] is an array, (since it seems to contain $currUser['uid']['3d']), which will cause problems if you try and echo it...

Posted: Wed Aug 23, 2006 4:38 am
by onion2k
GM wrote:I think that your $currUser['uid'] is an array, (since it seems to contain $currUser['uid']['3d']), which will cause problems if you try and echo it...
$currUser comes from..

Code: Select all

$currUser = mysql_fetch_array($result);
.. there's no way $currUser['uid'] can be an array.

Posted: Wed Aug 23, 2006 4:57 am
by GM
OK - i was just looking at the code in the iframe part, which says $currUser['uid']['3d'] - which suggested that $currUser['uid'] is an array, and therefore an attempt to echo it would produce 'Array'.

You responded while I was typing, so I didn't see your response before I posted mine. I agree with you that $currUser is probably the problem.

Posted: Wed Aug 23, 2006 5:36 am
by jmansa
JayBird | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


OK. Tryid to make an array...

Code: Select all

<?php

if (($_GET['uid']) && (is_numeric($_GET['uid']))) {
$userid = $_GET['uid'];

$dbhost = 'myhost';
$dbuser = myusername;
$dbpass = 'mypassword';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die                    ("Error connecting to mysql: " . mysql_error());

$dbname = 'mydatabase';
mysql_select_db($dbname);

//var_dump($uid);
 
$query="SELECT * FROM users WHERE uid='".$uid."'"; 
$result=mysql_query($query) or die("Unable to find requested user");
$currUser = mysql_fetch_array($result);

$iframe = array();
while($r = mysql_fetch_row($result)) {
    $iframe[] = array('uid'=>$r[0],'3d'=>$r[1]);
	sort($array); }	

?>
Still i get no response....? Any ideas...


JayBird | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Aug 23, 2006 5:47 am
by onion2k
Right. Lets go back to the drawing board here.

1. What is coming from your database? Show us the table fields.

2. What parameters are required to show the iframe?

Posted: Wed Aug 23, 2006 7:00 am
by jmansa
The tables are as follows...
uid
name
adress1
adress2
area
city
email
3d
I want to show all the fields regardless of the "3d" field is set to "yes" or "no". I want to show the iframe if the "3d" is set to "yes". The "3d" field is set to "enum" with a yes/no choice.

Hope thats enough!

Posted: Wed Aug 23, 2006 7:13 am
by onion2k
I've no idea what an enum field returns when you select it, but assuming it returns the value set rather than the index:

Code: Select all

$query="SELECT * FROM users WHERE uid='".$uid."'";
$result=mysql_query($query) or die("Unable to find requested user");
$currUser = mysql_fetch_array($result);

if ($currUser['3d'] == "yes") {
  echo "iframe";
} else {
  echo "no iframe";
}

Posted: Wed Aug 23, 2006 7:40 am
by jmansa
SUPER!!! It did the job but.... Just one little error left. It gets the iframe but not with the html page it should. It shows the "index" page in the iframe but should be showing something else. Any idea???

Code: Select all

<?php if ($currUser['3d'] == "yes") { 
	echo '<iframe src= "/users/' . $currUser['uid'] . '.html" width="510" height="345" frameborder="0" scrolling="no"></iframe>';} 
	else {
	echo "";}
	?>

Posted: Wed Aug 23, 2006 8:29 am
by onion2k
Sounds like your iframe src is wrong. Just look at the HTML that's being produced and you should be able to figure it out.

Posted: Wed Aug 23, 2006 8:39 am
by jmansa
Doesn't seem to be it! I tryid to make the source "http://www.cnn.com" but I still got the "index" page??? There must be something wrong in the code. Any idea?

Posted: Wed Aug 23, 2006 9:26 am
by feyd
$uid isn't created anywhere in the snippets posted. $userid is, but not $uid. This may be a source of problems.