Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

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

Posts: 115
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:
Please login or register to view this content. Registration is FREE

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
 
 
Register now for full access!
Old 11-04-2009, 04:53 PM Re: Not echoing rows
Super Talker

Posts: 115
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:
Please login or register to view this content. Registration is FREE

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: 115
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:
Please login or register to view this content. Registration is FREE

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: 115
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:
Please login or register to view this content. Registration is FREE

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,621
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 offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 11-04-2009, 06:35 PM Re: Not echoing rows
Super Talker

Posts: 115
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:
Please login or register to view this content. Registration is FREE

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: 80
Name: John
Location: Sacramento
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: 115
Name: Not Telling
Trades: 0
What would be an example of that? Like this?


Code:
<?= $row[Title] ?>
__________________
MY MSN:
Please login or register to view this content. Registration is FREE

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
Webmaster Talker

Posts: 744
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?
__________________
34343639363436653237373432303635373837303635363337 34323037343638363137343263323036343639363432303739 366637353366
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 11-05-2009, 01:20 PM Re: Not echoing rows
Skilled Talker

Posts: 80
Name: John
Location: Sacramento
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.39344 seconds with 12 queries