pedromas Posted April 4, 2009 Share Posted April 4, 2009 Hello I would like to start by informing you that I am recent php user (like three weeks) and therfore my lack of understanding or mistakes might seem trivial to you. I would also like to say that I have a book which is supposed to help me with PHP and MySQL but somehow every seconde example I practice on my php writer (php designer) comes as bugged out. I have also check online to see if this bug were only coming from the php writer but doesnt seem so. In other words in order to learn php I have been using the book, online tutorials, blogs and Forums. Now I am currently almost achieving what I want with php however out of my if statement I can only make one work and the other one has not been possible so far. I will shortly explain you what the logic behind the script is: 1st Connect to MySQL database 2nd I create three variables 3rd I start my if statement by asking if statement where the get variable city has to be logo 4th I have an if statement which echoes the according variable from the database ($all) --- until this step I have no had a problem and it generate what I want --- 5th I have an elseif statement where the get variabale city has to be an integer bigger than 0 6th I have sub if statement which should echo the according variable city from the database($city) <?php $mysqli = new mysqli(); $mysqli->init(); $mysqli->options(MYSQLI_INIT_COMMAND, 'SET @x=10'); $mysqli->options(MYSQLI_CLIENT_COMPRESS, 1); $mysqli->real_connect(localhost, user, pass, db, port); if(!$mysqli) { die('Connection not possible'); } $id = $_GET['city']; $all = 'SELECT*FROM destinations ORDER BY city;'; $city = 'SELECT*FROM objects WHERE city=".$id" '; if($id !='logo') { if($result = $mysqli->query($all)) { while($row=$result->fetch_array(MYSQLI_ASSOC)) { echo '<p><a href="test.php?city='.$row["id"].'"><b>- '.$row["city"].' - - - '.$row["country"].'</b></a></p>'; } } } elseif($id>int(0)) { if($result = mysqli->query($city)) { while($row=$result->fetch_array(MYSQLI_ASSOC)) { echo $city; } } } else { echo 'ERROR ('.$mysqli->sqlstate.'): '.$mysqli->error; } $mysqli->close(); ?> Any help will be kindly appreciate even if it is simply stating that my script is stupid and I should just from the beginning but any indication of how I should than start again will be even more appreciated. Thanks in advance Pedro Link to comment https://forums.phpfreaks.com/topic/152535-if-statement-mysqli-query/ Share on other sites More sharing options...
Fruct0se Posted April 4, 2009 Share Posted April 4, 2009 What errors are you getting? Or what is being outputted from the script so far? Link to comment https://forums.phpfreaks.com/topic/152535-if-statement-mysqli-query/#findComment-801152 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.