I Need Help Fast !

Discussion in 'MySQL' started by DareDevils, Dec 10, 2008.

  1. #1
    Somebody can fix this please?
    i am not so good at php.
    <table border="0" cellpadding="0" cellspacing="2" width="100%" class="zebra">
    <tbody>
    <tr>
      <td class="list1" width="60%" height="36">MUZICA NOUA MANELE</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%">&nbsp;</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='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>
    		</tr>
    	"; 
    	$i++;
    }
    ?>
    PHP:
    i am 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 1
    Code (markup):
    What i did wrong ??
     
    DareDevils, Dec 10, 2008 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Your problem is here:

    LIMIT " . ($page*$limit) . "," . $limit

    The ($page*$limit) is returning a negative value which doesn't work. Needs to be > 0.

    The $limit variable looks fine, so the problem is most likely with the $page variable. Where are you getting $page from? I don't see it in the above script.
     
    jestep, Dec 10, 2008 IP
  3. Krnl

    Krnl Peon

    Messages:
    60
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #3
    The problem is that you're using a newer version of MySQL that doesn't like the negative limit value that is returned if there are no results from the query - it worked fine in older versions...

    Find this line:
    
    $nr_pag=getTotalPages($limit);
    
    Code (markup):
    and add after it, the following line:
    
    if ( $limit < 0 ) { $limit = 0; }
    
    Code (markup):
     
    Krnl, Dec 10, 2008 IP
  4. Krnl

    Krnl Peon

    Messages:
    60
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #4
    good catch jestep. re: $page - where is it? Should be $nr_pag?
     
    Krnl, Dec 10, 2008 IP
  5. DareDevils

    DareDevils Active Member

    Messages:
    607
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    70
    #5
    From here:
    <?php echo "<a href='http://www.muzicamoka.com/muzica-noua-" . $categorie . "/page1.html'>" . $categorie . "</a>"; ?>
    PHP:
    and the above code is the category .... where should display the songs from a single category.
     
    DareDevils, Dec 10, 2008 IP