I am not a perfect coder, i don't know what i did wrong here: <table border="0" cellpadding="0" cellspacing="2" width="100%" class="zebra"> <tbody> <tr> <td class="list1" width="45%" height="36">MUZICA NOUA MINIMAL</td> <td class="list2" width="20%">DATE</td> <td class="list2" width="10%"> HITS </td> <td class="list2" width="15%"> UPLOADER </td> <td bgcolor="White" width="10%"> </td> </tr> <?php $con=mysql_pconnect($server,$user,$pass); if (!con) { die('Cannot connect to mysql ' . mysql_error()); } mysql_select_db($db); $limit=50; function getTotalPages($limit) { $res=mysql_query("SELECT COUNT(id) FROM melodie WHERE categorie='minimal'"); $total=mysql_result($res,0); $total=ceil($total/$limit); return $total; } $nr_pag=getTotalPages($limit); $query="SELECT * FROM melodie WHERE categorie='manele' ORDER BY data_ad DESC LIMIT " . ($page*$limit) . "," . $limit; $res=mysql_query($query) or die(mysql_error()); $i=($page*$limit)+1; while($row=mysql_fetch_array($res)) { $titluurl=str_replace(" ","-",$row['titlu']); $titluurl=str_replace("'","-",$titluurl); $titluurl=str_replace("`","-",$titluurl); $titluurl=str_replace("[","",$titluurl); $titluurl=str_replace("]","",$titluurl); $titluurl=str_replace("(","",$titluurl); $titluurl=str_replace(")","",$titluurl); $titluurl=str_replace(",","-",$titluurl); $titluurl=str_replace(".","-",$titluurl); $titluurl=str_replace(":","-",$titluurl); $titluurl=str_replace(";","-",$titluurl); $titluurl=str_replace("?","",$titluurl); $titluurl=str_replace("!","",$titluurl); $titluurl=str_replace("&","-",$titluurl); $titluurl=str_replace("@","",$titluurl); $titluurl=str_replace("*","",$titluurl); $titluurl=str_replace("^","",$titluurl); $titluurl=str_replace("%","",$titluurl); $titluurl=str_replace("#","",$titluurl); $titluurl=str_replace("=","",$titluurl); $titluurl=str_replace("+","-",$titluurl); $titluurl=str_replace("<","",$titluurl); $titluurl=str_replace(">","",$titluurl); $titluurl=str_replace("|","",$titluurl); $titluurl=str_replace("{","",$titluurl); $titluurl=str_replace("}","",$titluurl); $titluurl=str_replace("\"","",$titluurl); $titluurl=str_replace("/","",$titluurl); $titluurl=str_replace("~","-",$titluurl); $data=explode(" ",$row['data_ad']); $data=explode("-",$data['0']); echo "<tr> <td class='style4'>" . $i . " <a class='verslink' href='http://www.muzicamoka.com/muzica-noua/" . $row['categorie'] . "/" . $titluurl . "_" . $row['id'] . ".html' title='" . $row['titlu'] . "'>" . $row['titlu'] . "</a></td> <td><div align='center'><span class='style7'>" . $data['2'] . " " . traduluna($data['1']) . " " . $data['0'] . "</span></div></td> <td><div align='center'><span class='cc1'>" . $row['hits'] . "</span></div></td> <td><div align='center'><span class='cc1'>" . $row['uploader'] . "</span></div></td> <td bgcolor='White'><a href='http://www.muzicamoka.com/muzica-noua/" . $row['categorie'] . "/" . $titluurl . "_" . $row['id'] . ".html' title='" . $row['titlu'] . "'><img src='http://www.muzicamoka.com/include/download-r.jpg' alt='" . $row['categorie'] . " = " . $row['titlu'] . "' border='0'></a></td> </tr> "; $i++; } ?> PHP: I Get This error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-50,50' at line 1 Code (markup): Can u fix this piece of code ? please i need it fast.
i did that, but i am getting mysql error. and i don`t know why: THE ERROR SAYS: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-50,50' at line 1 Code (markup):
That error is likely caused by this: DESC LIMIT " .($page*$limit).",".$limit; As ads2help said, we don't see where $page is defined, but it appears to have a value of negative one (which is why it's becoming -50 after multiplication). Negative values are invalid as LIMIT parameters, hence the error. BTW, your markup needs some help too. That first TR looks like headers, why aren't those TH? IF you're going to put classes on them why are you inlining the width declaration in the markup? Your classes are presentational saying how it should appear not what they are, etc, etc. Oh, and your multiple str_replace would probably be better served as two str_replace accessing two arrays, or a preg_replace. $replaceArrayDash=array(' ',"'",'`',',',':',';','~','+'); $replaceArraySpace=array( '[',']','(',')','?','!','&','@','*','^','%','#','=','<', '>','|','"','/' ); $titleuurl=str_replace($replaceArrayDash,'-',$row['titlu']); $titleuurl=str_replace($replaceArraySpace,' ',$titleuurl); Code (markup): You'd want to define the arrays OUTSIDE the while loop. Other things are stuff like this: <td><div align='center'><span class='style7'>" . $data['2'] . " " . traduluna($data['1']) . " " . $data['0'] . "</span></div></td> Code (markup): I'm 99% certain that the span and div are completely unneccessary... as is the vague 'style7' class. The code does seem to be plagued by really vague names on everything. If I had written that it would probably look more like this: <?php function getTotalPages($limit) { $result=mysql_query("SELECT COUNT(id) FROM melodie WHERE categorie='minimal'"); $total=mysql_result($result,0); $total=ceil($total/$limit); return $total; } $connectDB=mysql_pconnect($server,$user,$pass); if (!connectDB) die('Cannot connect to mysql '.mysql_error()); mysql_select_db($db); $limit=50; $replaceArrayDash=array(' ',"'",'`',',',':',';','~','+'); $replaceArraySpace=array( '[',']','(',')','?','!','&','@','*','^','%','#','=','<', '>','|','"','/' ); $numberPages=getTotalPages($limit); $query="SELECT * FROM melodie WHERE categorie='manele' ORDER BY data_ad DESC LIMIT ".($page*$limit).",".$limit." "; $result=mysql_query($query) or die(mysql_error()); $index=($page*$limit)+1; echo ' <table class="muzica"> <tr> <th class="title">MUZICA NOUA MINIMAL</th> <th class="date">DATE</th> <th class="hits">HITS</th> <th class="uploader">UPLOADER</th> <th class="misc"></th> </tr> '; while ($row=mysql_fetch_array($res)) { $titleuurl=str_replace($replaceArrayDash,'-',$row['titlu']); $titleuurl=str_replace($replaceArraySpace,' ',$titleuurl); $data=explode(" ",$row['data_ad']); $data=explode("-",$data[0]); echo ' <tr> <td class="title"> ',$index,' <a href="http://www.muzicamoka.com/muzica-noua/', $row['categorie'],'/',$titluurl,'_',$row['id'],'.html" title="',$row['titlu'],'" > ',$row['titlu'],' </a> </td> <td class="date">',$data[2],' ',traduluna($data[1]),' ',$data[0],'</td> <td class="hits">',$row['hits'],'</td> <td class="uploader">',$row['uploader'],'</td> <td class="misc"> <a href="http://www.muzicamoka.com/muzica-noua/', $row['categorie'],'/',$titluurl,'_',$row['id'],'.html" title="',$row['titlu'],'" > <img src="http://www.muzicamoka.com/include/download-r.jpg" alt="',$row['categorie'],' = ',$row['titlu'],'" /> </a> </td> </tr> '; $index++; } ?> Code (markup): If you aren't going to be using inlined variables and instead exit your quotes to use them, then there was no reason to use the SLOWER double quotes in the first place. there is no reason to output the header until after you've checked all your 'die' conditions, a little bit of meaningful variable and classnames makes it clearer, as does some proper indentation/formatting. There's no reason to pop in and out of parsing mode so only one <?php per php file, those are headings so use a TH, I stripped all the presentational attributes and markup because that's what CSS is FOR, etc, etc... Looking at that split of the data_ad variable I would seriously consider using a single preg_split instead of the str_replace followed by explode. Of course that does nothing about the fact $page appears to contain -1.
Replaced my code with your own. now, i`m getting this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-50,50' at line 4 Code (markup):
Which is the same problem - that $page variable seems to contain negative one. Where in the code is that variable set?
Fixed. <?php $con=mysql_pconnect($server,$user,$pass); if (!con) { die('Cannot connect to mysql ' . mysql_error()); } mysql_select_db($db); $limit=50; function getTotalPages($limit) { $res=mysql_query("SELECT COUNT(id) FROM melodie WHERE categorie='manele'"); $total=mysql_result($res,0); $total=ceil($total/$limit); return $total; } $nr_pag=getTotalPages($limit); $query="SELECT * FROM melodie WHERE categorie='manele' ORDER BY data_ad DESC LIMIT " . ($page*$limit) . "," . $limit; $res=mysql_query($query) or die(mysql_error()); $i=($page*$limit)+1; while($row=mysql_fetch_array($res)) { $titluurl=str_replace(" ","-",$row['titlu']); $titluurl=str_replace("'","-",$titluurl); $titluurl=str_replace("`","-",$titluurl); $titluurl=str_replace("[","",$titluurl); $titluurl=str_replace("]","",$titluurl); $titluurl=str_replace("(","",$titluurl); $titluurl=str_replace(")","",$titluurl); $titluurl=str_replace(",","-",$titluurl); $titluurl=str_replace(".","-",$titluurl); $titluurl=str_replace(":","-",$titluurl); $titluurl=str_replace(";","-",$titluurl); $titluurl=str_replace("?","",$titluurl); $titluurl=str_replace("!","",$titluurl); $titluurl=str_replace("&","-",$titluurl); $titluurl=str_replace("@","",$titluurl); $titluurl=str_replace("*","",$titluurl); $titluurl=str_replace("^","",$titluurl); $titluurl=str_replace("%","",$titluurl); $titluurl=str_replace("#","",$titluurl); $titluurl=str_replace("=","",$titluurl); $titluurl=str_replace("+","-",$titluurl); $titluurl=str_replace("<","",$titluurl); $titluurl=str_replace(">","",$titluurl); $titluurl=str_replace("|","",$titluurl); $titluurl=str_replace("{","",$titluurl); $titluurl=str_replace("}","",$titluurl); $titluurl=str_replace("\"","",$titluurl); $titluurl=str_replace("/","",$titluurl); $titluurl=str_replace("~","-",$titluurl); $data=explode(" ",$row['data_ad']); $data=explode("-",$data['0']); echo "<tr> <td class='style4'>" . $i . " <a class='verslink' href='http://www.muzicamoka.com/muzica-noua/" . $row['categorie'] . "/" . $titluurl . "_" . $row['id'] . ".html' title='" . $row['titlu'] . "'>" . $row['titlu'] . "</a></td> <td><div align='center'><span class='style7'>" . $data['2'] . " " . traduluna($data['1']) . " " . $data['0'] . "</span></div></td> <td><div align='center'><span class='cc1'>" . $row['hits'] . "</span></div></td> <td><div align='center'><span class='cc1'>" . $row['uploader'] . "</span></div></td> <td bgcolor='White'><a href='http://www.muzicamoka.com/muzica-noua/" . $row['categorie'] . "/" . $titluurl . "_" . $row['id'] . ".html' title='" . $row['titlu'] . "'><img src='http://www.muzicamoka.com/include/download-r.jpg' alt='" . $row['categorie'] . " = " . $row['titlu'] . "' border='0'></a></td> "; echo "</tr>"; $i++; } ?> PHP: the $page variable was broken on the script. fixed. Thanks Guys.