Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   PHP (http://www.programmingforums.org/forum29.html)
-   -   php and mysql problem.. (http://www.programmingforums.org/showthread.php?t=13882)

teishu Aug 31st, 2007 11:45 AM

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

DaWei Aug 31st, 2007 12:17 PM

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.

teishu Aug 31st, 2007 2:41 PM

sorry, thats not supposed to be there m8, its aprt of a code i deleted and i missed a bit :(

DaWei Aug 31st, 2007 2:48 PM

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.

teishu Sep 1st, 2007 1:13 PM

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.

xavier Sep 1st, 2007 1:27 PM

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 -

DaWei Sep 1st, 2007 1:28 PM

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.

Dameon Sep 1st, 2007 3:48 PM

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.

teishu Sep 2nd, 2007 2:46 AM

can u recommend a good tutorial ?

teishu Sep 2nd, 2007 2:46 AM

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


All times are GMT -5. The time now is 12:40 PM.

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