php - mysqli create link based on row -


i want create link based on row value, , - more important, add variable - if row empty, text... if row have value, display this....

//i need display:

// if row season empty, resulting link must be

// web.com/movies/".$row["title_id"]."

// if row season have value, link must be: //web.com/series/".$row["title_id"]."/season/".$row["season"]."/episode/".$row["episode"]."

this base code.

        <?php     $servername = "localhost";     $username = "username";     $password = "password";     $dbname = "dbname";      // create connection     $conn = new mysqli($servername, $username, $password, $dbname);     // check connection     if ($conn->connect_error) {         die("connection failed: " . $conn->connect_error);     }       $sql = "select id, type, label, title_id, season, episode, approved links order id desc limit 30 offset 50";     $result = $last_id = $conn->query($sql);       if ($result->num_rows > 0)      {         echo "<table><tr><th>id</th><th>label</th><th>url</th><th>season</th><th>episode</th><th>approved</th></tr>";         // output data of each row         while($row = $result->fetch_assoc()) {             echo "<tr><td>".$row["id"]."</td><td>".$row["label"]."</td>"; // --------------------------------------------------------------             echo "<td><a href='http://web.com/(variables here)'>";             echo " ".$row["title_id"]."</a></td>"; // --------------------------------------------------------------     //i need display:     // if row season empty, resulting link must     // web.com/movies/".$row["title_id"]."     // if row season have value, link must be:   //web.com/series/".$row["title_id"]."/season/".$row["season"]."/episode/".$row["episode"]."     // -----------------------------------------             echo "<td>".$row["season"]."</td><td>".$row["episode"]."</td><td>".$row["approved"]."</td></tr>";         }         echo "</table>";     } else {         echo "0 results";     }     $conn->close();     ?> 

as stated in comments, using reserved mysql keyword: type. query not working properly. can't tell because haven't set checks make sure working. can either put backticks around so:

select id, `type` 

or change name of key in database (i'd recommend approach, titletype). until fix this, nothing work in php.

once have fixed this, how generate results, inside while loop (i'm assuming mean episode value):

if (empty($row['episode'])) {      echo 'web.com/movies/'.$row["title_id"]; } else {      echo 'web.com/series/'.$row['title_id'].'/season/'.$row['season'].'/episode/'.$row["episode"]; } 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -