Reply
Old 11-04-2009, 04:40 PM Not echoing rows
Super Talker

Posts: 109
Name: Not Telling
Trades: 0
I would like this script to echo the values from the row with the id 2.

PHP Code:
<?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.
__________________
MY MSN: Sith717@Hotmail.com
PHP, HTML, and CSS Coding, Logo and Web Design - Professionally done.
PM me anytime for HTML, PHP or web design help. I will be glad to help you out.
sith717 is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 11-04-2009, 04:53 PM Re: Not echoing rows
Super Talker

Posts: 109
Name: Not Telling
Trades: 0
I updated the code to this

PHP Code:
<?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); 
while (
$row mysql_fetch_assoc($result)) 
{
   echo 
$row['FirstName'];
   echo 
$row['LastName'];
   echo 
$row['MiddleName'];
}
?>
And I get this error:

Quote:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/runehost/public_html/update2.php on line 8
__________________
MY MSN: Sith717@Hotmail.com
PHP, HTML, and CSS Coding, Logo and Web Design - Professionally done.
PM me anytime for HTML, PHP or web design help. I will be glad to help you out.
sith717 is offline
Reply With Quote
View Public Profile
 
Old 11-04-2009, 04:59 PM Re: Not echoing rows
Super Talker

Posts: 109
Name: Not Telling
Trades: 0
I fixed that now there is a new error:

Quote:
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 Code:
<?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'];
}
?>
__________________
MY MSN: Sith717@Hotmail.com
PHP, HTML, and CSS Coding, Logo and Web Design - Professionally done.
PM me anytime for HTML, PHP or web design help. I will be glad to help you out.
sith717 is offline
Reply With Quote
View Public Profile
 
Old 11-04-2009, 05:16 PM Re: Not echoing rows
Super Talker

Posts: 109
Name: Not Telling
Trades: 0
PHP Code:
<?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)) 
{
     echo 
'First Name: ';
   echo 
$row['FirstName']; 
     echo 
'<br>Last Name: ';
 echo 
$row['LastName'];
      echo 
'<br>Middle Name: ';
   echo 
$row['MiddleName'];
}
?>
FIXED IT!
__________________
MY MSN: Sith717@Hotmail.com
PHP, HTML, and CSS Coding, Logo and Web Design - Professionally done.
PM me anytime for HTML, PHP or web design help. I will be glad to help you out.
sith717 is offline
Reply With Quote
View Public Profile
 
Old 11-04-2009, 05:43 PM Re: Not echoing rows
tripy's Avatar
Do not try this at home!

Posts: 3,176
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
I was about to say it...
Your query in the post #3 is malformed.

A correct query is
Code:
SELECT [fields list]
FROM [tables list]
WHERE [conditions]
A condition must always evaluate to something.
Thus the
Code:
WHERE FirstName, LastName, MiddleName
is wrong.
It could be
Code:
WHERE FirstName IS NOT NULL
AND (
  MiddleName IS NOT NULL
  OR 
  LastName IS NOT NULL
)
for example.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is online now
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 11-04-2009, 06:35 PM Re: Not echoing rows
Super Talker

Posts: 109
Name: Not Telling
Trades: 0
So is my code correct? 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 Code:
 <?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 Code:
<?php $row['MiddleName'?>
or
PHP Code:
<link rel="stylesheet" type="text/css" href="<?php $row['Url'?>/css/style.css" />
or
PHP Code:
    <title><?php $row['WebsiteTitle'?></title>


Like that? Or I have to have it echo?
__________________
MY MSN: Sith717@Hotmail.com
PHP, HTML, and CSS Coding, Logo and Web Design - Professionally done.
PM me anytime for HTML, PHP or web design help. I will be glad to help you out.

Last edited by sith717; 11-04-2009 at 06:39 PM..
sith717 is offline
Reply With Quote
View Public Profile
 
Old 11-04-2009, 07:01 PM Re: Not echoing rows
Skilled Talker

Posts: 61
Name: John
Trades: 0
PHP Code:
<?= $row[0?>
Envision_frodo is offline
Reply With Quote
View Public Profile
 
Old 11-04-2009, 07:12 PM Re: Not echoing rows
Super Talker

Posts: 109
Name: Not Telling
Trades: 0
What would be an example of that? Like this?


Code:
<?= $row[Title] ?>
__________________
MY MSN: Sith717@Hotmail.com
PHP, HTML, and CSS Coding, Logo and Web Design - Professionally done.
PM me anytime for HTML, PHP or web design help. I will be glad to help you out.
sith717 is offline
Reply With Quote
View Public Profile
 
Old 11-05-2009, 02:53 AM Re: Not echoing rows
lizciz's Avatar
Ultra Talker

Posts: 333
Name: Mattias Nordahl
Location: Sweden
Trades: 0
PHP Code:
<?= $var ?>
is a short version of
PHP Code:
<?php echo $var?>
So in your case, you could do
PHP Code:
<?php echo $row['Title']; ?>
I'm not sure, but wasn't this short version going to be removed in some php version?
__________________
596f75206d65616e20796f752063616e2061637475616c6c79 207265616420746869733f
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 11-05-2009, 01:20 PM Re: Not echoing rows
Skilled Talker

Posts: 61
Name: John
Trades: 0
Quote:
I'm not sure, but wasn't this short version going to be removed in some php version?
I hope not & as for the shorthand:
PHP Code:
// ## Worst: If you used $row = mysql_fetch_array($rs) then:
<?= $row[0?> or <?= $row['column_name'?> will work.
// ## Better: If you used $row = mysql_fetch_assoc($rs) then:
Only <?= $row['column_name'?> will work.
// ## Best: If you used $row = mysql_fetch_row($rs) then:
Only <?= $row[0?> will work.
Envision_frodo is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Not echoing rows
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.13973 seconds with 13 queries