Echo PHP array as HTML? - php

Okay, so I've literally spent all day trying to achieve this and have gotten nowhere.
I am creating a flipbook (using turn.js).
I have names and cause of death stored in a MySQL database.
I want to print 5 names and their cause of death on each page.
To add a page in turn.js, all i have to do is add a in
So i load the name and cause of death values into arrays, and then echo a whole div however with the array variable.
I'm really having trouble getting this into code.
At the moment I have managed to get this onto seperate pages, but how would i get it to print only 5 on a page, and then create a new page (untill there are no more names)
Here is what i have so far.
<?php
$dbc = mysql_connect('localhost', 'xxxx', 'xxxxxxx');
if (!$dbc) {
die('Not Connected: ' . mysql_error());
}
$db_selected = mysql_select_db("xxxxxx", $dbc);
if (!$db_selected)
{
die ("Can't Connect : " . mysql_error);
}
$query = "SELECT * FROM TABLE";
$result = mysql_query($query);
$victim = array();
$cod = array();
$count = 0;
while ($row = mysql_fetch_assoc($result)) {
$victim['$count'] = $row['Victim'];
$cod['$count'] = $row['COD'];
$count++;
}
?>
<div id="deathnote">
<div style="background-image:url(images/coverpage.jpg);"></div>
<div style="background-image:url(images/page1.jpg);"></div>
<div style="background-image:url(images/page2.jpg);"></div>
<div style="background-image:url(images/page3.jpg);"></div>
<div style="background-image:url(images/page4.jpg);"></div>
<div style="background-image:url(images/page5.jpg);"></div>
<?php
for ($x=0; $x=$count; $x++) {
echo "<div style='background-image:url(images/page5.jpg);'></div><div class='content'><div class='name'>" . $victim['$x'] . "</div><div class='cod'>" . $cod['$x'] . "</div></div></div>";
}
?>
Any help will be GREATLY appreciated.
Thanks in advance, guys :)

Take a look at the $_GET variable http://php.net/manual/de/reserved.variables.get.php there you can set variables in the URL like http://lol.de/?form=1&to=5
$from = $_GET['from'];
$to = $_GET['to'];
if(!is_numeric($from) || !is_numeric($to)) die('SQL Injection');
$count = $to - $from;
$query = "SELECT * FROM TABLE LIMIT ".$from-",".$count;
Then you create a dynamic link, where you add 5 to $from and $to.
Not tested, just a Idea.

Check the last two line on your code, e.g.:
for ($x=0; $x=$count; $x++) {
echo "<div style='background-image:url(images/page5.jpg);'></div><div class='content'><div class='name'>" . $victim['$x'] . "</div><div class='cod'>" . $cod['$x'] . "</div></div></div>";
Change them to:
$onPage = 5;
$currentPage = 1;
for ($x=0; $x=$count; $x++) {
if (($x % $onPage) == 0)
{
echo "<div style='background-image:url(images/page" . $currentPage . "jpg);'></div>";
$currentPage++;
}
echo "<div class='content'>"
. "<div class='name'>" . $victim['$x'] . "</div>"
. "<div class='cod'>" . $cod['$x'] . "</div>"
. "</div>";
}
You can play around with the "modulus" operator - %, to achieve the result you need.

Try below code.
$recordPerPage = 5;
<?php
for ($x=1; $x<=$count; $x++) {
if($x <= $recordPerPage ) {
echo "<div style='background-image:url(images/page".$x.".jpg);'></div><div class='content'><div class='name'>" . $victim['$x'] . "</div><div class='cod'>" . $cod['$x'] . "</div></div></div>";
}
$x = $recordPerPage;
$recordPerPage += $recordPerPage;
}
?>
Hope this will help to you!
Cheers!

This may help you.
<?php
$recordPerPageCount = 5;
$pageCount = 1;
for ($x=0; $x<$count; $x++) {
if($x % $recordPerPageCount == 0) {
//This block will execute each time after diplaying five records in a page
$pageCount++;
}
echo "<div style='background-image:url(images/page".$pageCount.".jpg);'></div><div class='content'><div class='name'>" . $victim['$x'] . "</div><div class='cod'>" . $cod['$x'] . "</div></div></div>";
}
?>

Related

Put results in different divs depending on what comes out of the database?

How it looks:
https://jsfiddle.net/jef2L8m6/
How it should look:
https://jsfiddle.net/jef2L8m6/1/
I know it looks really bad, this is just for testing purposes only.
Some of the Backend Code:
<?php //Selects all of the logged in users messages.
$name = $_SESSION["name"];
$con = mysqli_connect('localhost','root','','chat');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"ajax_demo");
$sql="SELECT * FROM `chat` ORDER BY date";
$result = mysqli_query($con,$sql);
$numrows = mysqli_num_rows($result);
if( $numrows == "0" or !isset($_SESSION["name"])){
echo "<div class='msg'>You are not registered (Or there are no messages to display)</div>";
exit();
}else{
echo "";
}
echo "<div class='msg_container'>";
while($row = mysqli_fetch_array($result)) {
echo "<div class='msg_user'>";
echo "<div class='username_user'><span>" . $row['username'] . "</span></div>";
echo "<div class='message_user'><span>" . $row['message'] . "</span></div>";
echo "</div>";
}
echo "";
mysqli_close($con);
?>
Thank you so much for taking your time to read this.
I am trying to figure out how I would change the div tags of each separate user depending on their name?
Is there any way to do this using PHP, I have tried doing 2 separate query's of one that selects just the users messages and another that selects everyones (excluding the users)
But none of them worked due to it not ordering them correctly.
Could I somehow change the div's using PHP if the username that comes out is not equal to the username in the session?
Thank's so much, if you don't think I explained this very well please give me some feedback and I will change/add what you need, THANK YOU!
Thank you so much "u_mulder", you have been very helpful in making me think of a simple way to solve this problem.
I was thinking way too complex for something so simple!
Here is the final code for anyone who this may help:
while($row = mysqli_fetch_array($result)) {
$class_msg = "msg";
$class_username = "username";
$class_message = "message";
if ($row['username'] == $_SESSION['name']) {
$class_msg = "msg_user";
$class_username = "username_user";
$class_message = "message_user";
}
echo "<div class='$class_msg'>";
echo "<div class='$class_username'><span>" . $row['username'] . "</span></div>";
echo "<div class='$class_message'><span>" . $row['message'] . "</span></div>";
echo "</div>";
}
while($row = mysqli_fetch_array($result)) {
$class = 'msg';
if ($row['username'] == $_SESSION['name']) {
$class = 'msg_user';
}
echo "<div class='" . $class . "'>";
// other codes here
}

Add pagination to my search engine

How can I add pagination to a search engine results page?
I have build a search engine but there are hundreds of thousands of results for every search so I want to add pages to it.
The results of the search engine are outputted in a table.
I have started to learn php and sql recently...
How can I add those pages?
I have tried this so far but with no success:
<?php
$con = mysqli_connect(xxxx);
mysqli_select_db($con, 'Data') or die("could not find the database!");
$output = '';
$results_per_page = 1000;
//positioning
if(isset($_GET['search']))
{
$starttime = microtime(true); //TIME
$searchkey = $_GET['search'];
$query = mysqli_query($con, "SELECT * FROM table1 WHERE email LIKE '%$searchkey%'") or die("Could not search") ;
$count = mysqli_num_rows($query);
// count number of pages for the search
$number_of_pages = ceil($count/$results_per_page);
// determine which page number visitor is currently on
if (!isset($_GET['page']))
{
$page = 1;
}
else
{
$page = $_GET['page'];
}
// LIMIT
$this_page_first_result = ($page-1)*$results_per_page;
if ($count == 0)
{
echo "</br>";
$output = 'There are no search results !' ;
}
else
{
echo '<table class="myTable">';
echo "<tr><th>aaa</th><th>bbb</th></tr>";
$query = mysqli_query($con, "SELECT * FROM table1 WHERE email LIKE '%$searchkey%' LIMIT " . $this_page_first_result . ',' . $results_per_page" ") or die("Could not search") ;
while ($row = mysqli_fetch_array($query))
{
$email = preg_replace('/(' . $searchkey . ')/i', '<mark>\1</mark>', $row["aaa"]);
$password = $row['bbb'];
echo "<tr><td>";
echo $aaa;
echo "</td><td>";
echo $bbb;
echo "</td></tr>";
$output = '</table>';
}
//echo "</table>";
$endtime = microtime(true);
$duration = $endtime - $starttime;
echo "</br>";
if ($count == 1)
{
echo "<div class=resinfo>";
echo '<div>'."1 result was found for '$searchkey' in $duration seconds.".'</div>'.'</br>';
echo "</div>";
}
else
{
echo "<div class=resinfo>";
echo '<div>'."$count results were found for '$searchkey' in $duration seconds.".'</div>'.'</br>';
echo "</div>";
}
}
echo $output;
}
//LINKS to other pages
for ($page = 1; $page<=$number_of_pages;$page++){
echo '' . $page . '';
}
?>
What have I done wrong, what can I improve to make it work?
Thanks a lot for your help!
It is not a good idea to build a pagination from scratch, instead use a lib like this: https://github.com/KnpLabs/knp-components/blob/master/doc/pager/intro.md

"Next" button doesn't refresh page with next 25 results

I have the code below and am trying to get the next 25 results from my sql table to appear on page. However, whenever I click the next button, no information is displayed. I have my offset = ($page - 1) * $items_per_page......I'm struggling to figure this out as it seems so simple compared the other code I've written, but is proving to be very elusive to me....any assistance would be greatly appreciated. My primary issue is that the next link does not provide the next 25 results and I'm unable to determine why and how to correct.
echo "<h3 style='text-align:center;'>Welcome to the Exchange Portal, " . $row['name'] . "! </h3>";
$items_per_page = 25;
$sql_count = "SELECT pin, title, title2, email, phone FROM crown_acura";
$result_cnt = mysqli_query($conn, $sql_count);
if(false === $result_cnt) {
throw new Exception('Query failed with: ' . mysqli_error());
} else {
$row_count = mysqli_num_rows($result_cnt);
// free the result set as you don't need it anymore
//mysqli_free_result($result_cnt);
}
echo $row_count;
echo " ";
if (!isset($_GET['Page'])) {
$Page = 1;
} else {
$Page = $_GET['Page'];
}
echo $page;
echo " ";
$page_count = 0;
if (0 === $row_count) {
// maybe show some error since there is nothing in your table
} else {
// determine page_count
$page_count = (int)ceil($row_count / $items_per_page);
// double check that request page is in range
if($page > $page_count) {
// error to user, maybe set page to 1
$page = 1;
}
}
echo " ";
echo $page_count;
echo " ";
echo $items_per_page;
$offset = ($page-1)*$items_per_page;
//echo $paging_info;
//echo " ";
echo "<br />";
//Query for displaying results
$list_sql = "SELECT pin, title, title2, email, phone FROM crown_acura LIMIT $offset, $items_per_page";
$result_query = $conn->query($list_sql);
//Table for displaying query results
echo "<table class='verify'>";
echo "<tr >";
echo "<td><h3>Name</h3></td><td> </td><td><h3>E-mail</h3></td><td><h3>Phone</h3></td>";
echo "</tr>";
for($i = 1; $i<= $page_count; $i++) {
if ($result_query->num_rows > 0) {
// output data of each row
while($row3 = mysqli_fetch_array($result_query)) {
echo "<tr>";
echo "<td class='dltd2 dlcl'>" . $row3["title"] . "</td><td>" . $row3["title2"] . "</td><td><a href='mailto:" . $row3['email'] . "'>" . $row3["email"] . "</a> </td><td>" . $row3["phone"] . " </td>";
echo "</tr>";
}
} else {
echo "0 results";
}
}
echo "<tr></tr>";
$next_page = $page + 1;
$last_page = $page - 1;
if($paging_info['curr_page'] <= 1) {
echo "<tr>";
echo "<td></td><td colspan='2'><a class='loadlink' href='" . $_PHP_SELF . "'>Next 25</a></td><td></td>";
echo "</tr>";
} elseif ($paging_info['curr_page'] < $page_count) {
echo "<tr>";
echo "<td></td><td><a href='" . $_PHP_SELF . "?page=" . $last_page . "'>Prev 25</a></td><td><a href='" . $_PHP_SELF . "?page=" . $next_page . "'>Next 25</a></td><td></td>";
echo "</tr>";
} elseif ($paging_info['curr_page'] === $page_count) {
echo "<tr>";
echo "<td></td><td colspan='2'><a href='" . $_PHP_SELF . "?page=" . $last_page . "'>Prev 25</a></td><td></td>";
echo "</tr>";
}
echo "</table>";
}
}
}
Have you tried to run the rendered SQL.
Output to browser:
"SELECT pin, title, title2, email, phone FROM crown_acura LIMIT $offset, $items_per_page"
try this... and change $page for different values (2,3,...,etc)
<?php
$items_per_page = 25;
$sql_count = "SELECT pin, title, title2, email, phone FROM crown_acura";
$result_cnt = mysqli_query($conn, $sql_count);
if (false === $result_cnt) {
throw new Exception('Query failed with: ' . mysqli_error());
} else {
$row_count = mysqli_num_rows($result_cnt);
// free the result set as you don't need it anymore
//mysqli_free_result($result_cnt);
}
echo $row_count;
echo " ";
if (!isset($_GET['Page'])) {
$Page = 1;
} else {
$Page = $_GET['Page'];
}
echo $page;
echo " ";
$page_count = 0;
if (0 === $row_count) {
// maybe show some error since there is nothing in your table
} else {
// determine page_count
$page_count = (int)ceil($row_count / $items_per_page);
// double check that request page is in range
if ($page > $page_count) {
// error to user, maybe set page to 1
$page = 1;
}
}
echo " ";
echo $page_count;
echo " ";
echo $items_per_page;
$offset = ($page - 1) * $items_per_page;
//echo $paging_info;
//echo " ";
echo "<br />";
//Query for displaying results
$list_sql = "SELECT pin, title, title2, email, phone FROM crown_acura LIMIT $offset, $items_per_page";
$result_query = $conn->query($list_sql);
echo ("RESULTS: ".$result_query->num_rows());
?>

php code not working after php.ini file reset

My service provider reset my php.ini file on me. My php code has not changed but now none of my functions are working?
I am running php.ini 5.2 what would I need to turn on, or off, to get the following code to work again?
Thank you in advance for your help
function characterListPost() {
global $wpdbNew;
$q = "SELECT id, ch_position, ch_name, ch_image, ch_description, ch_age, ch_like, ch_dislike FROM characters ORDER BY ch_position";
$rows = $wpdbNew->get_results($q,ARRAY_A);
// start with nonsense value to force a heading
$previous_season = 0;
$outputTwo='';
$i = 1;
foreach ($rows as $row) {
$outputTwo.= "<div class=\"characterbox\" id=\"div{$i}\">";
$i++;
$outputTwo.= "<div class=\"ch_name\">{$row["ch_name"]}</div>";
$outputTwo.= "<div><image class=\"ch_image\" id=\"ch_image{$row["id"]}\" alt=\"character image TBA\" src=\"{$row["ch_image"]}\" /></div>";
$outputTwo.= "<div class=\"ch_description\"><p>{$row["ch_description"]}</p></div>";
$outputTwo.= "<div class=\"ch_age\"><b>Age:</b> {$row["ch_age"]}</div>";
$outputTwo.= "<div class=\"ch_like\"><b>Like:</b> {$row["ch_like"]}</div>";
$outputTwo.= "<div class=\"ch_dislike\"><b>Dislike:</b> {$row["ch_dislike"]}</div>";
$outputTwo.= "<div class=\"Down10px clear\"></div>";
$outputTwo.= "</div>";
}
// echo test successful but $outputTwo will not display?
echo 'Connected successfully';
return $outputTwo;
}
?>
I tested the db code and it works so by process of elimination the problem must be between my php.ini file and the function code above
<?php
$wpdbNew = new wpdb('myacc.myhost.com', 'myusername', 'mypassword', 'mydbname');
if (!$wpdbNew) {
die('Could not connect: ' . mysql_error());
}
The following are already On inside php.ini
allow_url_fopen = On
allow_url_include = On
register_long_arrays = On
register_globals = On
Second part, based on provided answer below, getting the following code to work
EDIT got it to work by removing foreach ($rows as $row) {
All set, everything is working!
<?php
episodeListPost();
function episodeListPost() {
$host = 'mydomain.com';
$user = 'myusername';
$pass = 'mypassword';
$data = 'dbname';
$cn = mysql_connect($host, $user, $pass) or die(mysql_error());
mysql_select_db($data, $cn) or die(mysql_error());
$sql = "SELECT id, season_num, temp_eps_num, eps_num, title, inspired, descrip FROM season ORDER BY season_num, temp_eps_num";
$result = mysql_query($sql, $cn) or die(mysql_error());
if($result) {
$previous_season = 0;
$outputOne='';
$i = 1;
while($row = mysql_fetch_assoc($result)) {
foreach ($rows as $row) {
$season = $row["season_num"];
if ($season != $previous_season){
$outputOne.= "<div class=\"seasonTitle\">Season $season</div>";
$previous_season = $season;
}
$outputOne.= "<div class=\"clear\">Episode: {$row["eps_num"]}</div>";
$outputOne.= "<div class=\"epsTitle\">Title: <span class=\"epsTitleOutput\">{$row["title"]}</span></div><div class=\"epsInsp\"> {$row["inspired"]}</div>";
$outputOne.= "<div class=\"epsDiscrip\">{$row["descrip"]}</div>";
$outputOne.= "<div class=\"Down10px\"></div>";
}
if($i == 1) { }
echo $outputOne;
mysql_free_result($result);
} else {
echo 'No results';
}
mysql_close($cn);
}
?>
The the following function. Most likely, your query is not returning any results, or the function $wpdbNew->get_results() is not returning any records.
function characterListPost() {
global $wpdbNew;
$q = "SELECT id, ch_position, ch_name, ch_image, ch_description, ch_age, ch_like, ch_dislike FROM characters ORDER BY ch_position";
$rows = $wpdbNew->get_results($q,ARRAY_A);
// start with nonsense value to force a heading
$previous_season = 0;
$outputTwo='';
$i = 1;
foreach ($rows as $row) {
$outputTwo.= "<div class=\"characterbox\" id=\"div{$i}\">";
$i++;
$outputTwo.= "<div class=\"ch_name\">{$row["ch_name"]}</div>";
$outputTwo.= "<div><image class=\"ch_image\" id=\"ch_image{$row["id"]}\" alt=\"character image TBA\" src=\"{$row["ch_image"]}\" /></div>";
$outputTwo.= "<div class=\"ch_description\"><p>{$row["ch_description"]}</p></div>";
$outputTwo.= "<div class=\"ch_age\"><b>Age:</b> {$row["ch_age"]}</div>";
$outputTwo.= "<div class=\"ch_like\"><b>Like:</b> {$row["ch_like"]}</div>";
$outputTwo.= "<div class=\"ch_dislike\"><b>Dislike:</b> {$row["ch_dislike"]}</div>";
$outputTwo.= "<div class=\"Down10px clear\"></div>";
$outputTwo.= "</div>";
}
// echo test successful but $outputTwo will not display?
echo 'Connected successfully.';
if($i == 1) { echo '<br />' . 'No Rows Found'; } else { echo '<br />' . $i . ' Rows Found'; }
return $outputTwo;
}
SECOND TEST
<?php
characterListPost();
function characterListPost() {
$host = '127.0.0.1';
$user = 'root';
$pass = '';
$data = 'test';
$cn = mysql_connect($host, $user, $pass) or die(mysql_error());
mysql_select_db($data, $cn) or die(mysql_error());
$sql = "SELECT id, ch_position, ch_name, ch_image, ch_description, ch_age, ch_like, ch_dislike FROM characters ORDER BY ch_position";
$result = mysql_query($sql, $cn) or die(mysql_error());
if($result) {
$previous_season = 0;
$outputTwo='';
$i = 1;
while($row = mysql_fetch_assoc($result)) {
$outputTwo.= "\n\n" . '<!--- ROW #' . $i . ' -->' . "\n";
$outputTwo.= '<div class="characterbox" id="div' . $i . '">' . "\n";
$i++;
$outputTwo.= '<div class="ch_name">' . $row["ch_name"] . '</div>' . "\n";
$outputTwo.= '<div><image class="ch_image" id="ch_image' . $row["id"] . '" alt="character image TBA" src="' . $row["ch_image"] . '" /></div>' . "\n";
$outputTwo.= '<div class="ch_description"><p>' . $row["ch_description"] . '</p></div>' . "\n";
$outputTwo.= '<div class="ch_age"><b>Age:</b> ' . $row["ch_age"] . '</div>' . "\n";
$outputTwo.= '<div class="ch_like"><b>Like:</b> ' .$row["ch_like"] . '</div>' . "\n";
$outputTwo.= '<div class="ch_dislike"><b>Dislike:</b> ' . $row["ch_dislike"] . '</div>' . "\n";
$outputTwo.= '<div class="Down10px clear"></div>' . "\n";
$outputTwo.= '</div>' . "\n";
}
if($i == 1) { echo '<br />' . 'No Rows Found'; } else { echo '<br />' . $i . ' Rows Found'; }
echo '<textarea>' . $outputTwo . '</textarea>';
mysql_free_result($result);
} else {
echo 'No results';
}
mysql_close($cn);
}
?>
HACK AROUND
Replacing the function with this should work. Do not forget to call 'characterListPost()' wherever this is supposed to be output.
function characterListPost() {
$host = '127.0.0.1';
$user = 'root';
$pass = '';
$data = 'test';
$cn = mysql_connect($host, $user, $pass) or die(mysql_error());
mysql_select_db($data, $cn) or die(mysql_error());
$sql = "SELECT id, ch_position, ch_name, ch_image, ch_description, ch_age, ch_like, ch_dislike FROM characters ORDER BY ch_position";
$result = mysql_query($sql, $cn) or die(mysql_error());
$return = "";
if($result) {
$previous_season = 0;
$outputTwo='';
$i = 1;
while($row = mysql_fetch_assoc($result)) {
$outputTwo.= "<div class=\"characterbox\" id=\"div{$i}\">";
$i++;
$outputTwo.= "<div class=\"ch_name\">{$row["ch_name"]}</div>";
$outputTwo.= "<div><image class=\"ch_image\" id=\"ch_image{$row["id"]}\" alt=\"character image TBA\" src=\"{$row["ch_image"]}\" /></div>";
$outputTwo.= "<div class=\"ch_description\"><p>{$row["ch_description"]}</p></div>";
$outputTwo.= "<div class=\"ch_age\"><b>Age:</b> {$row["ch_age"]}</div>";
$outputTwo.= "<div class=\"ch_like\"><b>Like:</b> {$row["ch_like"]}</div>";
$outputTwo.= "<div class=\"ch_dislike\"><b>Dislike:</b> {$row["ch_dislike"]}</div>";
$outputTwo.= "<div class=\"Down10px clear\"></div>";
$outputTwo.= "</div>";
}
// if($i == 1) { echo '<br />' . 'No Rows Found'; } else { echo '<br />' . $i . ' Rows Found'; }
$return = $outputTwo;
mysql_free_result($result);
// } else {
// echo 'No results';
}
mysql_close($cn);
return $return;
}

click on a link in a table, then check in what row the link was

What I want to make is this:
I am making a blog. Now I want a query in my mysql-database that finds all the information that is in there. After that it should echo the title's of the blog's on my site in a table.
Then I would like to give people a choice which blog they would like to see. So when they click on the first title they will see the content of that blog.
So now the problem is that I don't know how I can make href's on every title that all go to another php file. In that file it should know which row/title is clicked and then it should make another query in the database that will find the content of that title. Then it should echo it on the site.
I got the table finished. I also know how to make the href's to the other page. the only thing I need to know is which title/href is clicked.
Is it possible to make this with php only? if yes, please explain me how.
I hope I am clear in what i would like to make.
EDIT: this is my code so far:
<?php
session_start();
$connectie = mysql_connect('localhost', 'root', 'usbw');
if ($connectie == false){
echo 'Er is iets fout gegaan met de connectie van de database';
}
if (mysql_select_db('dldatabase', $connectie) == false) {
echo 'Er kon geen verbinding met de database gemaakt worden';
}
$query = "Select *
from forum";
$resultaat = mysql_query($query, $connectie);
echo "<table border='1'>
<tr>
<th>Tijd</th>
<th>Gebruikersnaam</th>
<th>Titel</th>
</tr>";
`while($row = mysql_fetch_array($resultaat))
{
$_SESSION['row'] = $row;
echo "<tr>";
echo "<td>" . $row['Tijd'] . "</td>";
echo "<td>" . $row['Gebruikersnaam'] . "</td>";
echo "<td>" . '<a class="formtitellink" href="forumdocument.php">' . $row['Titel'] . '</a>' . "</td>";
echo "</tr>";
}
echo "</table>";`
this is the blog page
and this is where the content of the blog should beĀ±
session_start();
$row = $_SESSION['row'];
$row = $row + 1;
$query = "Select titel, inhoud
from forum
where `ID` = '$row'";
$resultaat = mysql_query($query, $connectie);
echo "$resultaat";
You can always use a framework like Wordpress, but if you want this kind of structure from scratch then you should read more about URL manipulation and use of GET parameters.
Simplest solution will be:
Create a page say post.php
Now every time you want a post to be displayed, send it with get
parameter. For eg: "page.php?id=hello-world"
On post.php, you can read this "id" parameter and then fire a
query accordingly.
Then print the resultant data on page.php
You need to pages like first page and the second page to open as hyper link.
Here is the sample code:
<?php
echo '<table width="650"><p><tr><th style="margin-left: 10px; padding-right: 70px;"></th>
<th style="width: 350px; ">Item for sale</th> <th>Location</th> <th>Posted</th></tr></table>';
$query1 = "select id from tblads order by priority desc LIMIT 10 OFFSET 1";
$result1 = mysql_query($query1);
$i1 = 0;
while ($row1 = mysql_fetch_row($result1))
{
$count1 = count($row1);
$y1 = 0;
while ($y1<$count1)
{
$c_row1 = current($row1);
$id = $c_row1;
next($row1);
$y1 = $y1 + 1;
//////TABLE
echo'<style> th{padding:0;}</style> ';
echo '<table style=" table-layout:fixed; order-collapse: collapse; " width="650">';
echo '<tr> <th> </th> <th style="width:350px;"> </th> <th style=""></th> <th style="width:100px;"></th></tr>';
$query = "select image,details, location, date from tblads where id=$id";
$result = mysql_query($query);
if (!$result) {$message = 'ERROR:' . mysql_error();return $message;}
else
{ $i = $i1;
$i = 0;
while ($row = mysql_fetch_row($result))
{
echo '<tr> ';
$count = count($row);
$y = 0;
while ($y < $count)
{
$c_row = current($row);
echo '<td style="">' . $c_row . '</td>';
next($row);
$y = $y + 1;
}
echo ' </tr>';
$i = $i + 1;
}
}
}
echo'</table>'; //Content TABLE CLOSE
}
mysql_free_result($result); mysql_close($con);
?>
Then the second page view.php to be opened by the hyperlink:
<?php
$id=$_GET['id'];
$query = "select image, details, location, price, date, id from tblads where id=$id";
$result = mysql_query($query);
if (!$result)
{
$message = 'ERROR:' . mysql_error();
return $message;
}
else
{ $i = 0;
echo '<table><p><tr>';
while ($i < mysql_num_fields($result))
{
$meta = mysql_fetch_field($result, $i);
echo '<th>' . $meta->name . '</th>';
$i = $i + 1;
}
echo '<th>View</th></tr>';
$i = 0;
while ($row = mysql_fetch_row($result))
{
echo '<tr>';
$count = count($row);
$y = 0;
while ($y < $count)
{
$c_row = current($row);
echo '<td>' . $c_row . '</td>';
next($row);
$y = $y + 1;
}
echo '<td></td> </tr>';
$i = $i + 1;
}
echo' </p></table>';
mysql_free_result($result);
mysql_close($con);
}
?>

Categories