
![]() |
xlspecial
Ok, I am a complete noob at this
phpstuff but I am trying to modify some code. Currently it outputs links only for subfolders where I need it to use a variable (might not be correct terminology) to decide weather to build the link for a subfolder or subdomain.It accesses my database and randomly chooses a domain then a random keyword. I'm about 50/50 with domains using subfolders and subdomains so I'd like to get this to detect which it is. In my domain table in the DB there is a column called ip_based. In this column a 0 indicates a subfolder domain while a 1 indicates a subdomain site. Here is the code: <? php$base=$_GET['base']; $base = str_replace('.' ,'', $base); $base=$base."links.txt"; $temp=0; $filename = 'rdmlinks/'.$base; //echo $filename; if (file_exists($filename)) { } else { $fh = fopen($filename, 'w') or die("can't open file"); $nu=3;////number of loop to go trough all install -you can change it ! while ($temp < $nu) { $temp++; require "/home/xxxx/public_html/xxxx/includes/config. php";$db = mysql_connect($config['db']['host'] . ":" . $config['db']['port'], $config['db']['username'], $config['db']['password']); if (!$db) { print "<h1>Connect Error</h1>"; } mysql_select_db($config['db']['name']); $z=0; $nb=rand(1,5); // random number of links default 1 to 5 links while($z < $nb){ //select Random domain $query="SELECT domain_id,domain FROM domain ORDER BY rand() Limit 1"; $result=mysql_query($query); $num=mysql_numrows($result); $i=0; while ($i < $num) { $predomain_id=mysql_result($result,$i,"domain_id"); $domain_id = $predomain_id; $predomain=mysql_result($result,$i,"domain"); $domain = $predomain; $i++; } //select random kw from domain $query="SELECT keyword FROM main_keywords WHERE domain_id=$domain_id ORDER BY rand() Limit 1"; $result=mysql_query($query); $num=mysql_numrows($result); $i=0; while ($i < $num) { $kw=mysql_result($result,$i,"keyword"); $kw2 = str_replace('-' ,'', $kw); $kw = str_replace(' ' ,'-', $kw); $i++; } $stringData = "<a href="http://www." . $domain . "/".$kw."">" . $kw2 . "</a>"; fwrite($fh, $stringData); $stringData = " "; fwrite($fh, $stringData); echo '<center>'; echo ''; echo ' '; echo '</center>'; $z++; } mysql_close(); } } $file = fopen($filename, "r"); while (!feof($file)) { // write file with data $k = fgets($file, 1024); $k = str_replace('\' , '' , $k); echo '<center>'; echo $k; echo '</center>'; } ?> I want it to build the link like this if ip_based is a 0; $stringData = "<a href="http://www." . $domain . "/".$kw."">" . $kw2 . "</a>"; And like this if ip_based is a 1: $stringData = "<a href="http://www." .$kw. "." . $domain . "/""">" . $kw2 . "</a>"; It writes the output to a text file in rdmlinks folder. Thanks for any help you might be able to offer on this. I'm trying to learnthis stuff but am having a very hard time of it.perkiset
Hey XL -
Just wanted you to know that I keep pressing "Mark Unread" on this post because I haven't had the time to think through it, but didn't want you to think you were being neglected ![]() I'll look at it soon, /p |

Thread Categories

![]() |
![]() |
Best of The Cache Home |
![]() |
![]() |
Search The Cache |
- Ajax
- Apache & mod_rewrite
- BlackHat SEO & Web Stuff
- C/++/#, Pascal etc.
- Database Stuff
- General & Non-Technical Discussion
- General programming, learning to code
- Javascript Discussions & Code
- Linux Related
- Mac, iPhone & OS-X Stuff
- Miscellaneous
- MS Windows Related
- PERL & Python Related
- PHP: Questions & Discussion
- PHP: Techniques, Classes & Examples
- Regular Expressions
- Uncategorized Threads