Russia Posted November 4, 2009 Share Posted November 4, 2009 I would like this script to echo the values from the row with the id 2. <?php error_reporting(E_ALL); ini_set('display_errors', '1'); require_once ('inc/config.php'); $query = "SELECT FirstName, LastName, MiddleName FROM testing WHERE id = '2'"; $result = mysql_query ($query); while ($row = mysql_fetch_assoc($result)) { echo $row['FirstName']; echo $row['LastName']; echo $row['MiddleName']; } ?> There are also no errors or warnings or notices. Quote Link to comment https://forums.phpfreaks.com/topic/180323-script-not-echoing-rows/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 4, 2009 Share Posted November 4, 2009 Either inc/config.php is doing something to stop code execution or there are no rows with an id = '2' Quote Link to comment https://forums.phpfreaks.com/topic/180323-script-not-echoing-rows/#findComment-951237 Share on other sites More sharing options...
Russia Posted November 4, 2009 Author Share Posted November 4, 2009 I fixed that now there is a new error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 'LastName', 'MiddleName'' at line 1 <?php error_reporting(E_ALL); ini_set('display_errors', '1'); require_once ('inc/config.php'); $query = "SELECT * FROM testing WHERE FirstName, LastName, MiddleName"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array ($result)) { echo $row['FirstName']; echo $row['LastName']; echo $row['MiddleName']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/180323-script-not-echoing-rows/#findComment-951238 Share on other sites More sharing options...
mrMarcus Posted November 4, 2009 Share Posted November 4, 2009 your WHERE clause makes no sense. Quote Link to comment https://forums.phpfreaks.com/topic/180323-script-not-echoing-rows/#findComment-951239 Share on other sites More sharing options...
Russia Posted November 4, 2009 Author Share Posted November 4, 2009 So what do I change it to? I am trying to make it show... Quote Link to comment https://forums.phpfreaks.com/topic/180323-script-not-echoing-rows/#findComment-951240 Share on other sites More sharing options...
mikesta707 Posted November 4, 2009 Share Posted November 4, 2009 a Where clause is a boolean condition. I have no clue what you are trying to do. What is your where clause supposed to do? Quote Link to comment https://forums.phpfreaks.com/topic/180323-script-not-echoing-rows/#findComment-951245 Share on other sites More sharing options...
Russia Posted November 4, 2009 Author Share Posted November 4, 2009 I am trying to echo the rows from the table 'testing' and the 3 columns are 'firstname', 'lastname', 'middlename' I know its kinda confusing. Quote Link to comment https://forums.phpfreaks.com/topic/180323-script-not-echoing-rows/#findComment-951246 Share on other sites More sharing options...
mrMarcus Posted November 4, 2009 Share Posted November 4, 2009 you're trying to run, and run fast before you even walk. you need to read up on the different manuals, and sift through the millions of online resources relevant to mysql and php. SQL syntax is incredibly straight forward .. SELECT something FROM a table WHERE something is equal, not equal, LIKE, BETWEEN, etc., etc. when you have: WHERE FirstName, LastName, MiddleName what are you expecting it to do? when you read it over, what are you hoping that it's going to do? honestly, you need to slow down, find some resources (online or a book)/tutorials (there's tons out there), on how to do the most basic mysql queries with PHP .. search this site, i guarantee you'll find what you're looking for. that's all i got for now. Quote Link to comment https://forums.phpfreaks.com/topic/180323-script-not-echoing-rows/#findComment-951255 Share on other sites More sharing options...
PFMaBiSmAd Posted November 4, 2009 Share Posted November 4, 2009 From the mysql manual - SELECT Syntax SELECT [ALL | DISTINCT | DISTINCTROW ] [HIGH_PRIORITY] [sTRAIGHT_JOIN] [sql_SMALL_RESULT] [sql_BIG_RESULT] [sql_BUFFER_RESULT] [sql_CACHE | SQL_NO_CACHE] [sql_CALC_FOUND_ROWS] select_expr [, select_expr ...] [FROM table_references [WHERE where_condition] [GROUP BY {col_name | expr | position} [ASC | DESC], ... [WITH ROLLUP]] [HAVING where_condition] [ORDER BY {col_name | expr | position} [ASC | DESC], ...] [LIMIT {[offset,] row_count | row_count OFFSET offset}] [PROCEDURE procedure_name(argument_list)] [iNTO OUTFILE 'file_name' export_options | INTO DUMPFILE 'file_name' | INTO var_name [, var_name]] [FOR UPDATE | LOCK IN SHARE MODE]] Quote Link to comment https://forums.phpfreaks.com/topic/180323-script-not-echoing-rows/#findComment-951284 Share on other sites More sharing options...
Russia Posted November 4, 2009 Author Share Posted November 4, 2009 I have fixed that problem. Now i got a question... I would like to echo it separately in different places of my webpage, can I just do this? At the top of the page <?php require_once ('inc/config.php'); $query = "SELECT * FROM testing"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array ($result)) ?> Around the webpage. <?php $row['MiddleName'] ?> or <link rel="stylesheet" type="text/css" href="<?php $row['Url'] ?>/css/style.css" /> or <title><?php $row['WebsiteTitle'] ?></title> Like that? Or I have to have it echo? Quote Link to comment https://forums.phpfreaks.com/topic/180323-script-not-echoing-rows/#findComment-951323 Share on other sites More sharing options...
kenrbnsn Posted November 4, 2009 Share Posted November 4, 2009 If you want a value to appear on your web site, you must send it to the web server either with echo, print, print_f, or some other method. Ken Quote Link to comment https://forums.phpfreaks.com/topic/180323-script-not-echoing-rows/#findComment-951324 Share on other sites More sharing options...
Russia Posted November 4, 2009 Author Share Posted November 4, 2009 So how would I show it? <title><?php print(".$row['WebsiteTitle']."); ?></title> Like that??? Quote Link to comment https://forums.phpfreaks.com/topic/180323-script-not-echoing-rows/#findComment-951331 Share on other sites More sharing options...
Russia Posted November 5, 2009 Author Share Posted November 5, 2009 It still doesnt work: <?php error_reporting(E_ALL); ini_set('display_errors', '1'); require_once ('inc/config.php'); $query = "SELECT * FROM testing"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array ($result)) { ?> First Name: <?php $row['FirstName']; ?> <br>Last Name: <?php $row['LastName']; ?> <br>Middle Name: <?php $row['MiddleName']; ?> <? } ?> Quote Link to comment https://forums.phpfreaks.com/topic/180323-script-not-echoing-rows/#findComment-951393 Share on other sites More sharing options...
gizmola Posted November 5, 2009 Share Posted November 5, 2009 You need to make those lines at the bottom be: <?php echo $row['FirstName']; ?> etc. Quote Link to comment https://forums.phpfreaks.com/topic/180323-script-not-echoing-rows/#findComment-951399 Share on other sites More sharing options...
Russia Posted November 5, 2009 Author Share Posted November 5, 2009 Thanks it was as simple as that. Quote Link to comment https://forums.phpfreaks.com/topic/180323-script-not-echoing-rows/#findComment-951400 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.