UK Webmaster Talk - Online Marketing - SEO


 

Help With PHP Script.

This is a discussion on Help With PHP Script. within the Php and MySQL forums, part of the Programming / Scripting / Coding category; 20WMT? when my band gets updated (6:50pm GMT) if you can solve this for me. I get Parse error: parse ...


Go Back   UK Webmaster Talk - Online Marketing - SEO > Website Design & Development > Programming / Scripting / Coding > Php and MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Notices

Reply

 

LinkBack Thread Tools Display Modes
Old 30-04-2005, 23:47   #1 (permalink)
Senior Member
 
Join Date: Apr 2005
Posts: 1,088
iTrader: 0 / 0%
Departed is a name known to allDeparted is a name known to all
Default Help With PHP Script.

20WMT? when my band gets updated (6:50pm GMT) if you can solve this for me.
I get

Parse error: parse error, unexpected T_ELSE in /home/jdjokes/public_html/top10.php on line 7
when i access it;

heres the code:

PHP Code:
<?php
include("config.php");
$query=mysql_query("SELECT * FROM jokes ORDER BY rating DESC LIMIT 10");
if(
mysql_num_rows($query) == 0){
echo 
"There are no jokes currently in the top 10";
{
else{
echo 
'<table width="150" border="1">
<tr><td colspan="2">Joke</td></tr>'
;
$i=0;
while(
$r=mysql_fetch_array($query)){
$i++;
echo 
'<tr>
<td>'
$i'</td>
<td><a href="joke.php?j='
$r['num']. '">'$r['title']. '</a></td>
</tr>'
;
}
}
?>
So whats wrong with "else{" . :confused:
__________________
-Gary
Departed is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-05-2005, 00:04   #2 (permalink)
*poke* *poke*
 
Join Date: Apr 2005
Posts: 134
iTrader: 0 / 0%
mck9235 is on a distinguished road
Default

Try this:
PHP Code:
<?php
include("config.php");
$query=mysql_query("SELECT * FROM jokes ORDER BY rating DESC LIMIT 10");
if(
mysql_num_rows($query) == 0)
{
echo 
"There are no jokes currently in the top 10";
}
else
{
echo 
'<table width="150" border="1">
<tr><td colspan="2">Joke</td></tr>'
;
$i=0;
while(
$r=mysql_fetch_array($query)){
$i++;
echo 
'<tr>
<td>'
$i'</td>
<td><a href="joke.php?j='
$r['num']. '">'$r['title']. '</a></td>
</tr>'
;
}
}
?>
You had a bracket going the wrong way.
__________________
| - The Fast Track - |
Thanks to WMT for the new domain!
mck9235 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-05-2005, 00:13   #3 (permalink)
Senior Member
 
Join Date: Apr 2005
Posts: 1,088
iTrader: 0 / 0%
Departed is a name known to allDeparted is a name known to all
Default

We've half sorted it over msn. I know have the code:

PHP Code:
<?php 
include("config.php"); 
$query=mysql_query("SELECT * FROM `jokes` ORDER BY `rating` DESC LIMIT 10") or die(mysql_error());
if(
mysql_num_rows($query) == 0

echo 
"There are no jokes currently in the top 10"

else 

echo 
'<table width="150" border="1"> 
<tr><td colspan="2">Joke</td></tr>'

$i=0
while(
$r=mysql_fetch_array($query)){ 
$i++; 
echo 
'<tr> 
<td>'
$i'</td> 
<td><a href="joke.php?j='
$r['num']. '">'$r['title']. '</a></td> 
</tr>'



?>
And get "Unknown column 'rating' in 'order clause'" Now MySQL Doesnt want to work.... :confused:

(Sent some WMT? just for trying mck )
__________________
-Gary
Departed is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-05-2005, 08:35   #4 (permalink)
Super Moderator
 
Join Date: Mar 2005
Location: Herts, UK
Posts: 1,030
iTrader: 1 / 100%
monaghan is a jewel in the rough
Default

I'd replace
PHP Code:
$query=mysql_query("SELECT * FROM `jokes` ORDER BY `rating` DESC LIMIT 10"
with
PHP Code:
$query = <<< SQLEND
SELECT * 
FROM jokes
ORDER BY rating
DESC 
LIMIT 10
SQLEND;

$query=mysql_query($query)..... 
As your code gets more complex, then this will aid readability.

Any reason for putting quotes round the table & field names ?

Any reason for doing a select *, this is generally bad practise, do you actually need every field ? If not then you're returning data that's not needed and adding load to your host and delay to the execution of your script.
monaghan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-05-2005, 14:17   #5 (permalink)
*poke* *poke*
 
Join Date: Apr 2005
Posts: 134
iTrader: 0 / 0%
mck9235 is on a distinguished road
Default

I put the quotes around the field+table name. It's perfectly acceptable, and is a good thing to practice. I only started becuase right now thats the only way queries will run on my computer.
__________________
| - The Fast Track - |
Thanks to WMT for the new domain!
mck9235 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 01-05-2005, 22:18   #6 (permalink)
Super Moderator
 
Join Date: Mar 2005
Location: Herts, UK
Posts: 1,030
iTrader: 1 / 100%
monaghan is a jewel in the rough
Default

Quoting is acceptable, however only required when you use a reserved word or a non-alpha/numeric within a name.

Quoting can be good, however simple meaningful names avoiding any requirement for quoting would probably be far better and more protable as many SQL enqines use differing quoting methods.
monaghan is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Tags
php, script

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Survey Script matty005 Php and MySQL 2 23-05-2006 10:50
script that does this xeno Website Development Forum 2 02-04-2006 12:02
Need a script for my site nicklas Website Design Forum 5 12-10-2005 18:20
Your most complicated script Wistow Programming / Scripting / Coding 13 09-04-2005 20:43
Looking for Script cashoutusa Programming / Scripting / Coding 4 02-03-2005 19:23


All times are GMT +1. The time now is 18:35.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
UK Webmaster Forum © WebmasterTalk.co.uk | Design by Forbairt

Ad Management by RedTyger

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41