Hi, I am trying to make a link based on info stored in MySQL, the code I have got so far is

if (isset($_POST['search_now'])) {
    $result = mysql_query("SELECT * FROM bands WHERE BandName LIKE '%$BandName%'");  

$page = "<a href=\"http://www.website.com/$row['PageName']\">$row['BandName']</a>";

while($row = mysql_fetch_array($result)) { echo 'Band Name:  '; echo $row['BandName'] ." " . $row['Genre']; echo $page;  echo "<br />"; }

}

But I am getting: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in ... on line 14

I have never seen this error before, can anyone help?

Thanks

Recommended Answers

All 4 Replies

Hi, thanks for you help.

I don't understand the %s bit, when executed there is nothing %s, could you explain?

Thanks

I don't understand the %s bit, when executed there is nothing %s, could you explain?

The '%s' means that this is a placeholder for a string, which is later filled in with the value stated later. So the first '%s' would be filled in with '$row' while the second with '$row'.

The line of code that I gave you has to be placed within the WHILE loop. So:

if (isset($_POST['search_now'])) 
{
    $result = mysql_query("SELECT * FROM bands WHERE BandName LIKE '%$BandName%'");  


    while($row = mysql_fetch_array($result)) 
    { 
        $page = sprintf( "<a href='http://www.website.com/%s'>%s</a>" , $row['PageName']  , $row['BandName']  ) ;
        echo 'Band Name:  '; 
        echo $row['BandName'] ." " . $row['Genre']; 
        echo $page;  
        echo "<br />";
    }
}

This is because you wish to create a link, however in your first example, you was trying to populate the link with data that you did not have yet, as it was before the query to the database was run.

One more thing I would tidy the code up a bit more, having each command on a new line. Well I hope that this helps :)

Works perfectly, thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.