![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: May 2006
Posts: 49
Rep Power: 0
![]() |
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 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 ! |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
What the heck is this?
$data = echo "<tr> ....blah blah 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 |
|
|
|
|
|
#3 |
|
Programmer
Join Date: May 2006
Posts: 49
Rep Power: 0
![]() |
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 ! |
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#5 |
|
Programmer
Join Date: May 2006
Posts: 49
Rep Power: 0
![]() |
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 ! |
|
|
|
|
|
#6 |
|
Professional Programmer
|
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 ! |
|
|
|
|
|
#7 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#8 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
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 |
|
|
|
|
|
#9 |
|
Programmer
Join Date: May 2006
Posts: 49
Rep Power: 0
![]() |
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 ! |
|
|
|
|
|
#10 |
|
Programmer
Join Date: May 2006
Posts: 49
Rep Power: 0
![]() |
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 ! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|