Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/180323-script-not-echoing-rows/
Share on other sites

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'];
}
?>

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.

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]]

 

 

 

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?

 

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']; ?>
<?
}
?> 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.