Tuesday, 15 May 2012

php - show two or more links to the auto-write files from data in database -



php - show two or more links to the auto-write files from data in database -

i learning how auto write new file info in database. , follow tutorial: http://www.9lessons.info/2011/04/seo-friendly-urls-with-php.html

the tutorial give me want achieve. posted new post database file of publish.php, link of new post/file have posted seen in top of form. auto rewrite url got file of article.php.

it form:

<input type="text" name "title"/> <textarea name="body"></teaxtarea> <?php include('db.php'); function string_limit_words($string, $word_limit) { $words = explode(' ', $string); homecoming implode(' ', array_slice($words, 0, $word_limit)); } $blog=''; if($_server["request_method"] == "post") { $title=mysql_real_escape_string($_post['title']); $body=mysql_real_escape_string($_post['body']); $title=htmlentities($title); $body=htmlentities($body); $date=date("y/m/d"); $newtitle=string_limit_words($title, 6); $urltitle=preg_replace('/[^a-z0-9]/i',' ', $newtitle); $newurltitle=str_replace(" ","-",$newtitle); $url=$date.'/'.$newurltitle.'.html'; mysql_query("insert blog(title,body,url) values('$title','$body','$url')"); $blogurl="http://seo.website.com/$url"; } ?>

blow link new posted file.

<h2><a href="<?php echo $blogurl; ?>"><?php echo $blogurl; ?></a></h2>

what want know @ time is, how show links of data/file have posted database.

i have tried re-create paste line above this:

<h2><a href="<?php echo $blogurl; ?>"><?php echo $blogurl; ?></a></h2> <h2><a href="<?php echo $blogurl; ?>"><?php echo $blogurl; ?></a></h2>

however show same 2 links of 1 file info in database, while want shows different link of 2 files, instance: first link show file number 1, , sec link show file number 2 info in database.

please don't focus database driver of mysql use, still want larn stage.

.. if understand question correctly - need values , loop through each one. in question looks echoing same values repeatedly.

(pcode) $query = "select * blog"; $ret = $pdo->do( $query ); $blogurl="http://seo.website.com/"; foreach( $ret $row ) { echo "<h2><a href=" . $blogurl . $row->url . ">" . $row->title . "</a></h2>"; }

php mysql

No comments:

Post a Comment