Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 31st, 2007, 11:45 AM   #1
teishu
Programmer
 
Join Date: May 2006
Posts: 49
Rep Power: 0 teishu is on a distinguished road
php and mysql problem..

hi guys,
not posted for a few weeks but anyway, ive got a problem with part of a system im developing at work.

heres the code:

[php]
<?php
$db = mysql_connect("localhost", "Administrator", "pass"); //Server connection
mysql_select_db("learn_php",$db); //Select database on mysql server
$result = mysql_query("SELECT * FROM multi_data",$db); //send mysql query
$num_rows = mysql_num_rows($result); //retreive number of lines

for($i = 0;$i != $num_rows; $i += 1)
{
$query = mysql_query("SELECT `job_ref` FROM `frontscreen` WHERE `ID` = $i+1",$db);
$data =
echo "<tr>
<td
style=\"text-align: center; font-family: Helvetica,Arial,sans-serif;\"
valign=\"undefined\">"mysql_fetch_assoc($query)"</td>
<td
style=\"text-align: center; font-family: Helvetica,Arial,sans-serif;\"
valign=\"undefined\"></td>
<td
style=\"text-align: center; font-family: Helvetica,Arial,sans-serif;\"
valign=\"undefined\">23:41</td>
<td
style=\"text-align: center; font-family: Helvetica,Arial,sans-serif;\"
valign=\"undefined\">1:15</td>
<td
style=\"text-align: center; font-family: Helvetica,Arial,sans-serif;\"
valign=\"undefined\">3:15</td>
<td
style=\"text-align: center; font-family: Helvetica,Arial,sans-serif;\"
valign=\"undefined\">18:00 25/09/2007</td>
</tr>
";
}

?>
[/php]Im trying to retreive the data in the job_ref field for each ID row into the appropriate part of the html table, this is just the php section no the entire code for the page.

here is the error i get:

Parse error:  syntax error, unexpected T_ECHO in /var/www/sla/frontend.php on line 53
Any help would be great thanks !


The password in the above has been changed for security...
__________________
Intel Pentium M 1.73Ghz -- Sony Vaio -- 1024MB Ram -- Ubuntu 8.04
AMD Athlon X2 4200+ -- Asus V3-M2V890 -- 2GB Kingston -- Vista Ultimate 32bit
Intel C2D E4400 -- 2048MB GeIL - Windows XP SP2

ASCII stupid question, get a stupid ANSI !
teishu is offline   Reply With Quote
Old Aug 31st, 2007, 12:17 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
What the heck is this?
$data =
echo "<tr> ....blah blah
You can't assign an echo to a variable. Echo isn't actually a function, and if viewed as a function, its return is void.

If you want all that textual crap in $data, just assign it, THEN echo $data.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Aug 31st, 2007, 2:41 PM   #3
teishu
Programmer
 
Join Date: May 2006
Posts: 49
Rep Power: 0 teishu is on a distinguished road
sorry, thats not supposed to be there m8, its aprt of a code i deleted and i missed a bit
__________________
Intel Pentium M 1.73Ghz -- Sony Vaio -- 1024MB Ram -- Ubuntu 8.04
AMD Athlon X2 4200+ -- Asus V3-M2V890 -- 2GB Kingston -- Vista Ultimate 32bit
Intel C2D E4400 -- 2048MB GeIL - Windows XP SP2

ASCII stupid question, get a stupid ANSI !
teishu is offline   Reply With Quote
Old Aug 31st, 2007, 2:48 PM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Don't expect people to correctly debug code for you if you don't correctly produce it for them.

If you do produce error messages regarding some specific line, you should indicate the line unless your code/highlight tags result in a line-numbered display.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Sep 1st, 2007, 1:13 PM   #5
teishu
Programmer
 
Join Date: May 2006
Posts: 49
Rep Power: 0 teishu is on a distinguished road
its on this line:

<td
style=\"text-align: center; font-family: Helvetica,Arial,sans-serif;\"
valign=\"undefined\">"mysql_fetch_assoc($query)"</td>

do i need ". mysql_fetch_assoc($query) ." ? i seem to think it could be that... cant try it until monday at work tho.
__________________
Intel Pentium M 1.73Ghz -- Sony Vaio -- 1024MB Ram -- Ubuntu 8.04
AMD Athlon X2 4200+ -- Asus V3-M2V890 -- 2GB Kingston -- Vista Ultimate 32bit
Intel C2D E4400 -- 2048MB GeIL - Windows XP SP2

ASCII stupid question, get a stupid ANSI !
teishu is offline   Reply With Quote
Old Sep 1st, 2007, 1:27 PM   #6
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 373
Rep Power: 4 xavier is on a distinguished road
Send a message via Yahoo to xavier
Yes , you need that ... you have to concatenate the strings .
That being said, pick up a tutorial on php and mysql because what you'r doing there is VERY weird.

Instead of selecting all the rows at once, you're making them separate querys ?:eek:

Oh, and i'm not sure that mysql_fetch_assoc($query) will yield the results you want.

- pickup a tutorial -
__________________
Don't take life too seriously, it's not permanent !
xavier is offline   Reply With Quote
Old Sep 1st, 2007, 1:28 PM   #7
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Well, certainly you can't just put it there like you have it. The " after the > ends the echo string, then there's a missing semicolon.

If you want to concatenate strings you need the dot. mysql_fetc-assoc does not return a string, however, it returns an array.

I recommend consulting the documentation for the things you use. Even a brief review of PHP seems to be in order.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Sep 1st, 2007, 3:48 PM   #8
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
I don't know what you have in multi_data, but if all you are doing with it is determining the number of entries, it is silly for the database to return everything in the table. If you have 10 million rows some day, your database will stab you in your sleep.

SELECT COUNT(1) FROM `multi_data` makes more sense. Remember that for the future.

I doubt you have a good reason for performing that same query with an incrementing ID...the idea is to get only the relevant data in as few queries as possible.

I advise that you learn the basics of the language, read and understand some MySQL examples, and only then come back to this.
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270
Dameon is offline   Reply With Quote
Old Sep 2nd, 2007, 2:46 AM   #9
teishu
Programmer
 
Join Date: May 2006
Posts: 49
Rep Power: 0 teishu is on a distinguished road
can u recommend a good tutorial ?
__________________
Intel Pentium M 1.73Ghz -- Sony Vaio -- 1024MB Ram -- Ubuntu 8.04
AMD Athlon X2 4200+ -- Asus V3-M2V890 -- 2GB Kingston -- Vista Ultimate 32bit
Intel C2D E4400 -- 2048MB GeIL - Windows XP SP2

ASCII stupid question, get a stupid ANSI !
teishu is offline   Reply With Quote
Old Sep 2nd, 2007, 2:46 AM   #10
teishu
Programmer
 
Join Date: May 2006
Posts: 49
Rep Power: 0 teishu is on a distinguished road
no, i need to return all the rows in that table as its going to be a day job table, returns all the jobs for that day... i will change the ID to date at some point...
__________________
Intel Pentium M 1.73Ghz -- Sony Vaio -- 1024MB Ram -- Ubuntu 8.04
AMD Athlon X2 4200+ -- Asus V3-M2V890 -- 2GB Kingston -- Vista Ultimate 32bit
Intel C2D E4400 -- 2048MB GeIL - Windows XP SP2

ASCII stupid question, get a stupid ANSI !
teishu is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:22 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC