php - create dynamic link from Mysql table -


im trying create dynamic links post inside database table, cant figure out how create link, when user logged in.

i think this.

    <?php $articles = new articles();  foreach($articles->fetch_user_article($_get['uid']) $article) :?>  <a href="edit_articles.php?uid=<?php echo $_session['id']?>&article=<?php echo $article['id'];?>"><?php echo $article['title'];?></a>      <?php endforeach ?> 

this gives me link looks this

edit_articles.php?uid=5&article=213 

the article id:s correct db table.

now edit_articles.php file

$articles = new articles(); $article = $articles->fetch_user_article($_get['uid']);  echo $article['text']; 

but when im reach edit_articles.php file

undefined index: text 

and function

function fetch_user_article($uid){         $uid = (int)$uid;         $query = $this->link->query ("select id, title,text blog user_id = '{$uid}' ");         $tweet = array();         while(($row = $query->fetch(pdo::fetch_assoc)) !== false) {              $tweet[] = $row;         }         return $tweet;     } 

your function fetch_user_article returning more 1 article. use fecth articles.

$articles = $articles->fetch_user_article($_get['uid']);  foreach ( $articles $article ) {     echo $article['text']; } 

if want fetch_user_article return 1 article, field user_id of table blog should unique.

or have rewrite query

 select id, title,text blog user_id = '{$uid}' 

so gives 1 result, like:

      $article_id = $_get['article'];       select id, title,text blog id = '{$article_id}' 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -