array echo

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

array echo

Post by joecrack »

i made this script that has to print out an array
i know the SELECT looks strage .. but i tried it in phpmyadmin and its working.
so insted of the array i get this!

Parse error: parse error, unexpected $ in C:\Server\xampp\htdocs\inword.php on line 15

Code: Select all

<?php
$db = @mysql_connect('localhost','root','') OR die(mysql_error());
@mysql_select_db(safe,$db) OR die(mysql_error());

$sql ="SELECT sam_bestellung.customernr,sam_bestellung.hull,sam_bestellung.custrefnr,sam_bestellung.custrefname,
sam_date_val.incdate FROM sam_bestellung,sam_date_val WHERE sam_bestellung.projnr='159' AND sam_date_val.projnr='159' AND sam_bestellung.customernr='02.01.' AND sam_date_val.customernr='02.01.'";

$result = mysql_query($sql); 
$zeile = mysql_fetch_array($result); 
echo "{$zeile['customernr']} - {$zeile['hull']} - {$zeile['custrefname']} - {$zeile['incdate']}</p>';

mysql_close();


?>
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post by jmut »

Well, as a start you might try removing these @
turn on displaying errors...and switching on error_reporting(E_ALL).
Because the problem might be somewhere else...
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

Post by joecrack »

display errors are on - error_reporting(E_ALL) is on - @ are gone!!!
still same output
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

Code: Select all

<?php
$db = @mysql_connect('localhost','root','') OR die(mysql_error());
@mysql_select_db(safe,$db) OR die(mysql_error());

$sql ="SELECT sam_bestellung.customernr,sam_bestellung.hull,sam_bestellung.custrefnr,sam_bestellung.custrefname,
sam_date_val.incdate FROM sam_bestellung,sam_date_val WHERE sam_bestellung.projnr='159' AND sam_date_val.projnr='159' AND sam_bestellung.customernr='02.01.' AND sam_date_val.customernr='02.01.'";

$result = mysql_query($sql);
$zeile = mysql_fetch_array($result);
echo $zeile['customernr'].' - '.$zeile['hull'].' - '.$zeile['custrefname'].' - '.$zeile['incdate'].'</p>';

mysql_close();


?>
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

Post by joecrack »

Now its like this:

Code: Select all

<?php
error_reporting(E_ALL);
$db = mysql_connect('localhost','root','') OR die(mysql_error());
mysql_select_db(safe,$db) OR die(mysql_error());
$sql ="SELECT sam_bestellung.customernr,sam_bestellung.hull,sam_bestellung.custrefnr,sam_bestellung.custrefname,sam_date_val.incdate FROM sam_bestellung,sam_date_val WHERE sam_bestellung.projnr='159' AND sam_date_val.projnr='159' AND sam_bestellung.customernr='02.01.' AND sam_date_val.customernr='02.01.'";
$result = mysql_query($sql); 
$zeile = mysql_fetch_array($result); 

echo $zeile['customernr'].' - .'$zeile['hull'].' - '.$zeile['custrefname'].' - '.$zeile['incdate'].'</p>;

mysql_close();
?>
Still i get a damn ParseError:

Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in C:\Server\xampp\htdocs\inword.php on line 13
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

].'</p>; should be ].'</p>';
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

Do you actually read the errors? :?
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

Jenk wrote:Do you actually read the errors? :?
why? does there seem any doubt :roll:

@joecrack:

Code: Select all

echo $zeile['customernr'].' - .'$zeile['hull'].' - '.$zeile['custrefname'].' - '.$zeile['incdate'].'</p>;
should be

Code: Select all

echo $zeile['customernr'].' - '.$zeile['hull'].' - '.$zeile['custrefname'].' - '.$zeile['incdate'].'</p>';
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

n00b Saibot wrote:
Jenk wrote:Do you actually read the errors? :?
why? does there seem any doubt :roll:
That was pointed at joecrack, not you :P
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

Post by joecrack »

Okey nice nor i have the array printout.
So - my next question now i would like to know how i can print the array in different parts of a html document.
I can write like this:

$zeile['customernr'].' xyzxyzxyz blah blah </br> '.$zeile['hull'].' -

and its still working, but as soon as I do it like this:

echo Hello </br> $zeile['customernr'].' xyzxyzxyz blah blah </br> '.$zeile['hull'].


it is not working any more.
how can i solve this problem?
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

PLEASE! USE PHP TAGS WHEN POSTING CODE! you will easily find your solution. you just have to put quotes around the html/non php stuff then put a period in between the quotes where you want to echo out the php variables.
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

Post by joecrack »

:twisted: Praise Lord shiznatix :twisted:
thx a lot =)
joecrack
Forum Commoner
Posts: 99
Joined: Mon Oct 31, 2005 9:17 pm

Post by joecrack »

hi
but this just works if there are just some words and hml tags in between the array output.
because i tried to enter a hole html page (with many quotes and dots andsoon) and its not showing anything but parse errors.
the thing is i have to make a scipt that automaticly prints out a order confirmation for the customer and insert the array output in some parts.
If i do it like this:

Code: Select all

echo "<html><h1>sdfdsf</h1></br></br>".$zeile['yardcust']."sdfsdfds</br>".$zeile['hull'].' - '.$zeile['fax'].' - '.$zeile['incdate'].'</p>';
Its no problem.
But as soon as i want to add <style type="text/css">... </style> its not working.
I think this is just not the right way to solve the problem.
please HELP
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

you're going to need to escape the quotes in your HTML (they're conflicting with echo ""s quotes)

Code: Select all

<style type=\"text/css\">
instead of

Code: Select all

<style type="text/css">
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post by mickd »

if your php editor program doesnt have syntax highlighting i suggest to download and use one that does (lots mentioned in the general section in 1 of the stickys)

it helps because if you forget a ' or " or forget to close a " or ', the colour goes weird and makes it extremely easy to notice.
Post Reply