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, ); Link to comment https://forums.phpfreaks.com/topic/53447-solved-auto-linking/ 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>'; ?> Link to comment https://forums.phpfreaks.com/topic/53447-solved-auto-linking/#findComment-264115 Share on other sites More sharing options...
eric1235711 Posted May 29, 2007 Share Posted May 29, 2007 what kind of problems? Link to comment https://forums.phpfreaks.com/topic/53447-solved-auto-linking/#findComment-264123 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" ); Link to comment https://forums.phpfreaks.com/topic/53447-solved-auto-linking/#findComment-264127 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 Link to comment https://forums.phpfreaks.com/topic/53447-solved-auto-linking/#findComment-264129 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. Link to comment https://forums.phpfreaks.com/topic/53447-solved-auto-linking/#findComment-264131 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 Link to comment https://forums.phpfreaks.com/topic/53447-solved-auto-linking/#findComment-264135 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. Link to comment https://forums.phpfreaks.com/topic/53447-solved-auto-linking/#findComment-264136 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? Link to comment https://forums.phpfreaks.com/topic/53447-solved-auto-linking/#findComment-264138 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>'; ?> Link to comment https://forums.phpfreaks.com/topic/53447-solved-auto-linking/#findComment-264142 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 Link to comment https://forums.phpfreaks.com/topic/53447-solved-auto-linking/#findComment-264148 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? Link to comment https://forums.phpfreaks.com/topic/53447-solved-auto-linking/#findComment-264153 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 Link to comment https://forums.phpfreaks.com/topic/53447-solved-auto-linking/#findComment-264163 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 Link to comment https://forums.phpfreaks.com/topic/53447-solved-auto-linking/#findComment-264165 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 ); } Link to comment https://forums.phpfreaks.com/topic/53447-solved-auto-linking/#findComment-264203 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 />'; } ?> Link to comment https://forums.phpfreaks.com/topic/53447-solved-auto-linking/#findComment-264209 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.