lordphate Posted May 29, 2007 Share Posted May 29, 2007 okay so i'm tryin go to do a auto link thing and i'm running into some problems with my mysql statements $sql_query = "SELECT * FROM tags"; $result = mysql_query($sql_query) or die(mysql_error()); $result = mysql_fetch_assoc($result); foreach($result as $res){ $res["tag"] = $tag; $res["link"] = $link; } echo "Test".$tag; $keyword_array = array( $tag => $link, ); Quote Link to comment Share on other sites More sharing options...
per1os Posted May 29, 2007 Share Posted May 29, 2007 What are you trying to do exactly, you did not really explain anything. Just looking at that one suggestion is this: <?php $sql_query = "SELECT tag, link FROM tags"; $result = mysql_query($sql_query) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $keyword_array[$tag] = $link; } echo '<pre>' . print_r($keyword_array) . '</pre>'; ?> Quote Link to comment Share on other sites More sharing options...
eric1235711 Posted May 29, 2007 Share Posted May 29, 2007 what kind of problems? Quote Link to comment Share on other sites More sharing options...
lordphate Posted May 29, 2007 Author Share Posted May 29, 2007 What i'm trying to do is pull tag and link from the tags table Then assign EACH "tag" and "link" as $tag and $link here's the original array $keyword_array = array( "security" => "http://myscripts.itsp.info/security", "technology" => "http://myscripts.itsp.info/technology", "passport" => "http://myscripts.itsp.info/passport", "state department" => "http://myscripts.itsp.info/state department", "bruce" => "http://myscripts.itsp.info/bruce", "radio frequency" => "http://myscripts.itsp.info/radio frequency" ); Quote Link to comment Share on other sites More sharing options...
lordphate Posted May 29, 2007 Author Share Posted May 29, 2007 The problem i'm having is it's not echoing out $tag or $link with my code Quote Link to comment Share on other sites More sharing options...
per1os Posted May 29, 2007 Share Posted May 29, 2007 I just modified my code to correct a minor typo, try that and see if it gets you what you want. Quote Link to comment Share on other sites More sharing options...
lordphate Posted May 29, 2007 Author Share Posted May 29, 2007 With your code i get Array ( [] => ) 1 Quote Link to comment Share on other sites More sharing options...
per1os Posted May 29, 2007 Share Posted May 29, 2007 Crap, my bad another typo on my part. <?php $sql_query = "SELECT tag, link FROM tags"; $result = mysql_query($sql_query) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $keyword_array[$row['tag']] = $row['link']; } echo '<pre>' . print_r($keyword_array) . '</pre>'; ?> Run that and see what happens. Quote Link to comment Share on other sites More sharing options...
lordphate Posted May 29, 2007 Author Share Posted May 29, 2007 Array ( [http://www.packetstorm.com] => [http://www.indiana.in.us] => ) 1 Why is it in [] though? Quote Link to comment Share on other sites More sharing options...
per1os Posted May 29, 2007 Share Posted May 29, 2007 That is just a dump of the array. Try this maybe: <?php $sql_query = "SELECT tag, link FROM tags"; $result = mysql_query($sql_query) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $keyword_array[$row['tag']] = $row['link']; // removed the $ part so this should work now. $lastTag = $row['tag']; } echo '<a href="' . $keyword_array[$lastTag] . '">' . $lastTag . '</a><br />'; echo 'Array Structure<br /><pre>' . print_r($keyword_array) . '</pre>'; ?> Quote Link to comment Share on other sites More sharing options...
lordphate Posted May 29, 2007 Author Share Posted May 29, 2007 It's almost there! It's showing the URL and wanting to go to /State Quote Link to comment Share on other sites More sharing options...
lordphate Posted May 29, 2007 Author Share Posted May 29, 2007 okay so i swapped a couple things around and now it links correctly. But how do i put it into the original array? I've tried and it's not working correctly. am i not allowed to use variables into an array? Quote Link to comment Share on other sites More sharing options...
lordphate Posted May 29, 2007 Author Share Posted May 29, 2007 Okay hopefully this will be the last question: So i'm using your code, and it works perfectly with the FIRST field, but what about the rest of the fields. It only grabs the 1st set (state / url) it's not parsing the 2nd or 3rd, etc Quote Link to comment Share on other sites More sharing options...
per1os Posted May 29, 2007 Share Posted May 29, 2007 <?php $sql_query = "SELECT tag, link FROM tags"; $result = mysql_query($sql_query) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $keyword_array[$row['tag']] = $row['link']; // removed the $ part so this should work now. $lastTag = $row['tag']; } foreach ($keyword_array as $tag => $link) { echo '<a href="' . $keyword_array[$tag] . '">' . $link . '</a><br />'; } ?> www.php.net/foreach Quote Link to comment Share on other sites More sharing options...
lordphate Posted May 29, 2007 Author Share Posted May 29, 2007 <?php $sql_query = "SELECT tag, link FROM tags"; $result = mysql_query($sql_query) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $keyword_array[$row['tag']] = $row['link']; // removed the $ part so this should work now. $lastTag = $row['tag']; } foreach ($keyword_array as $tag => $link) { echo '<a href="' . $keyword_array[$tag] . '">' . $link . '</a><br />'; } ?> would it be this or $sql_query = "SELECT tag, link FROM tags"; $result = mysql_query($sql_query) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $keyword_array[$row['link']] = $row['tag']; $lastTag = $row['link']; $lastLink = $row['tag']; } foreach ($keyword_array as $lastTag => $lastLink ){ $keyword_array = array( $lastTag => $lastLink ); } Quote Link to comment Share on other sites More sharing options...
per1os Posted May 29, 2007 Share Posted May 29, 2007 It would be what I posted above. I do not understand where you are getting at with trying to re-define the keyword array? That makes no sense at all. the lasttag and lastlink are not required, just something created for testing. <?php $sql_query = "SELECT tag, link FROM tags"; $result = mysql_query($sql_query) or die(mysql_error()); while ($row = mysql_fetch_assoc($result)) { $keyword_array[$row['tag']] = $row['link']; // removed the $ part so this should work now. } foreach ($keyword_array as $tag => $link) { echo '<a href="' . $keyword_array[$tag] . '">' . $link . '</a><br />'; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.