Jump to content

What am i doing wrong here?


adamjblakey

Recommended Posts

I am just trying to assign my results to an array but cannot see what i am doing wrong here as the results do not seem to be assigning

 

Here is the code:

 

$strippagename = str_replace("-", " ",$_GET['title']);
$sql = "SELECT id,title FROM `recipes` WHERE `category2` = '$strippagename'";
$res = mysql_query($sql);
$i = -1;
while ($row = mysql_fetch_assoc($res)) 
{
  $cat_url = strtr($row['title'], "éèêàëâúóíáABCDEFGHIJKLMNOPQRSTUVWXYZ. ","eeeaeauoiaabcdefghijklmnopqrstuvwxyz--");
  $cat_url = ereg_replace('[^a-zA-Z0-9_-]', '', $cat_url);

  $tmp = array(
        'id' => $row['id'],
        'title' => $row['title'],
        'caturl' => $cat_url
        );
  $results[$i++] = $tmp;
} 

echo "<pre>";
print_r($results);
echo "</pre>";

 

 

What am i doing wrong here?

I am just trying to assign my results to an array but cannot see what i am doing wrong here as the results do not seem to be assigning

 

Here is the code:

 

Code:

 

// get all the recipes from the table

$strippagename = str_replace("-", " ",$_GET['title']);

$sql = "SELECT * FROM recipes WHERE category2 = '$strippagename'";

 

// looping through the table to get all results

$res = mysql_query($sql) or die (mysql_error()."<p>$sql</p>");

$results = array();

$i=0;

while (list($title) = mysql_fetch_row($res)) {

 

$cat_url = strtr($title, "éèêàëâúóíáABCDEFGHIJKLMNOPQRSTUVWXYZ. ","eeeaeauoiaabcdefghijklmnopqrstuvwxyz--");

$cat_url = ereg_replace('[^a-zA-Z0-9_-]', '', $cat_url);

 

$tmp = array(

'id' => $r['id'],

'title' => $title,

'caturl' => $cat_url

 

);

$results[$i++] = $tmp;

}

 

Cheers,

Adam

 

Link to comment
https://forums.phpfreaks.com/topic/63510-what-am-i-doing-wrong-here/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.