need help with code.

Discussion in 'PHP' started by izlik, Nov 16, 2007.

  1. #1
    The code bellow trows me an error on line 11... can anyone help me as to why is do that ? :(

    <?php
    $con = mysql_connect("localhost","asd","das");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("asd", $con);
    $result = mysql_query('SELECT * FROM `images` WHERE `tags` LIKE '%' . $_GET['tag'] . '%');
    while($row = mysql_fetch_array($result))
      {
      echo '<a href='http://mydomain.com/out.php/'.$row['name'].'</a>';
      echo "<br/>";
      }
    ?>			
    PHP:
     
    izlik, Nov 16, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    $result = mysql_query("SELECT * FROM `images` WHERE `tags` LIKE '%" . mysql_real_escape_string($_GET['tag']) . "%'");
    
    PHP:
     
    nico_swd, Nov 16, 2007 IP
  3. izlik

    izlik Well-Known Member

    Messages:
    2,399
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    185
    #3
    thanks nico! :)

    after putting that in i get Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/izlik/public_html/tags.php on line 14

    and using crimson Editor i already se one on line 14 :(

    
    <?php
    $con = mysql_connect("localhost","asd","asd");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("das", $con);
    $result = mysql_query("SELECT * FROM `images` WHERE `tags` LIKE '%" . mysql_real_escape_string($_GET['tag']) . "%'");
    while($row = mysql_fetch_array($result))
      {
      echo '<a href='http://mydomain.com/out.php/'.$row['name'].'</a>';
      echo "<br/>";
      }
    ?>
    PHP:
     
    izlik, Nov 16, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    
      echo '<a href="http://mydomain.com/out.php/">' .$row['name'].'</a>';
    
    PHP:
     
    nico_swd, Nov 16, 2007 IP
  5. izlik

    izlik Well-Known Member

    Messages:
    2,399
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    185
    #5
    now this one poped up up! :(

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/izlik/public_html/tags.php on line 11
    
    <?php
    $con = mysql_connect("localhost","asd","asd");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("asd", $con);
    $result = $result = mysql_query("SELECT * FROM `images` WHERE `tags` LIKE '%" . mysql_real_escape_string($_GET['tag']) . "%'");
    while($row = mysql_fetch_array($result))
      {
      echo '<a href="http://mydomain/out.php/">' .$row['name'].'</a>';
      echo "<br/>";
      }
    ?>			
    	
    PHP:
     
    izlik, Nov 16, 2007 IP
  6. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #6
    test your query to see if it return something ..
     
    commandos, Nov 16, 2007 IP
  7. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #7
    
    <?php
    
    $con = mysql_connect("localhost","asd","asd") OR die('Could not connect: ' . mysql_error());
    mysql_select_db("asd", $con);
    
    $result = mysql_query("
    	SELECT *
    	FROM `images`
    	WHERE `tags`
    	LIKE '%" . mysql_real_escape_string($_GET['tag']) . "%'
    ")
    OR die(mysql_error());
    
    while($row = mysql_fetch_array($result))
    {
    	echo '<a href="http://mydomain/out.php/">' .$row['name'].'</a>';
    	echo "<br/>\n";
    }
    
    ?>
    
    PHP:
     
    nico_swd, Nov 16, 2007 IP
    izlik likes this.
  8. izlik

    izlik Well-Known Member

    Messages:
    2,399
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    185
    #8
    thanks a lot nicko, your just awsome! :) adding rep for you and thanks a lot! :)

    however i have one last question, is it someway to make this easy on the database to load? like let's say that there is a huge ammount of data to load and many people do it at the same time.
     
    izlik, Nov 16, 2007 IP
  9. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #9
    
    $filename = preg_replace('~\.[a-z0-9]+$~i', '.html', $row['name']);
    echo '<a href="http://mydomain/out.php/' . $filename .'">' .$row['name'].'</a>';
    
    PHP:
     
    nico_swd, Nov 16, 2007 IP
  10. izlik

    izlik Well-Known Member

    Messages:
    2,399
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    185
    #10
    thanks again nico :)

    i know i promised that was the last question, but i have another problem i just cant get my hand around "need to study more php" :(

    as you se in the code bellow i but a limit to 30 images. now i know "limit" has more parameters so that if there is more then 30 images it could make a "next page" avaliable to view the rest of the images. do you think you could help me with this?

    i know i asked a lot already but if you could help me with this i would love you forever! :)

    <?php
    
    $con = mysql_connect("localhost","asd","asd") OR die('Could not connect: ' . mysql_error());
    mysql_select_db("das", $con);
    
    $result = mysql_query("
        SELECT *
        FROM `images`
        WHERE `tags`
        LIKE '%" . mysql_real_escape_string($_GET['tag']) . "%'
        ORDER BY views DESC LIMIT 50
    ")
    OR die(mysql_error());
    
    while($row = mysql_fetch_array($result))
    {
        echo '<a href="http://mydomain.net/show.php/' .$row['id'].'_' .$row['name'].'"><img src="http://www.mydomain.net/out.php/t' .$row['id'].'_' .$row['name'].'"></a>';
        echo "<br/>\n";
    }
    
    ?>		
    PHP:
     
    izlik, Nov 16, 2007 IP