-
Jun 12th, 2015, 02:49 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] php help display news table records
Hello
Can anyone help me display my news table as it's not showing a record and also is given out any errors?.index.php
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
-
Jun 12th, 2015, 05:16 AM
#2
Re: php help display news table records
Originally Posted by Jamie_Garland
Hello
Can anyone help me display my news table as it's not showing a record and also is given out any errors?. index.php
I don't think people will help you unless you are more specific in what you are asking. And most will not even try to download the file if you have not provided any clear details regarding your doubt! So I would suggest you to edit your post and rephrase your question including more details about your problem, with the relevant piece of code.
That being said, I downloaded the file and did a quick look on it. What I can say is, you are still using the mysql_*() functions. If you are in the path of creating a new project, I would highly recommend you to use mysqli or PDO instead of this depreciated mysql functions. Other than that, I would suggest you to use escaping of the data that you read from the $_GET array. Otherwise, it could cause sql injections.
Apart from this, I don't see any issues while looking at the code quickly. Maybe you should tell us more about what the error is, or what the issue is, in detail!
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Jun 12th, 2015, 11:04 AM
#3
Thread Starter
Frenzied Member
Re: php help display news table records
Hello,
Sorry, what i mean is it wont display the info from the record on my site as you can see http://www.yansumkune.com.
PHP Code:
<?php include('styles/top.php'); ?>
<div id="left">
<?php
include("includes/connect.php");
if(isset($_GET['id'])){
$page_id = $_GET['id'];
$select_query = "select * from news where post_id='$page_id'";
$run_query = mysql_query($select_query);
while($row=mysql_fetch_array($run_query)){
$post_id = $row['post_id'];
$post_title = $row['post_title'];
$post_date = $row['post_date'];
$post_author = $row['post_author'];
$post_image = $row['post_image'];
$post_content =$row['post_content'];
?>
<h2>
<a href="pages.php?id=<?php echo $post_id; ?>">
<?php echo $post_title; ?>
</a>
</h2>
<p align="left">Published on: <b><?php echo $post_date; ?></b></p>
<p align="right">Posted by: <b><?php echo $post_author; ?></b></p>
<center><img src="images/<?php echo $post_image; ?>" width="500" height="300" /></center>
<p align="justify"><?php echo $post_content; ?></p>
<?php } }?>
</div>
<?php include('styles/bottom.php'); ?>
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
-
Jun 12th, 2015, 11:12 AM
#4
Re: php help display news table records
Originally Posted by Jamie_Garland
Hello,
Sorry, what i mean is it wont display the info from the record on my site as you can see http://www.yansumkune.com.
PHP Code:
<?php include('styles/top.php'); ?>
<div id="left">
<?php include("includes/connect.php"); if(isset($_GET['id'])){ $page_id = $_GET['id']; $select_query = "select * from news where post_id='$page_id'"; $run_query = mysql_query($select_query); while($row=mysql_fetch_array($run_query)){ $post_id = $row['post_id']; $post_title = $row['post_title']; $post_date = $row['post_date']; $post_author = $row['post_author']; $post_image = $row['post_image']; $post_content =$row['post_content']; ?> <h2> <a href="pages.php?id=<?php echo $post_id; ?>"> <?php echo $post_title; ?> </a> </h2> <p align="left">Published on:**<b><?php echo $post_date; ?></b></p> <p align="right">Posted by:**<b><?php echo $post_author; ?></b></p> <center><img src="images/<?php echo $post_image; ?>" width="500" height="300" /></center> <p align="justify"><?php echo $post_content; ?></p> <?php } }?>
</div> <?php include('styles/bottom.php'); ?>
Can you give me the exact link which you tried?
Also, are there any records in database for the table "news" ?
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Jun 12th, 2015, 11:21 AM
#5
Thread Starter
Frenzied Member
Re: php help display news table records
http://www.yansumkune.com there ment to show on the black piece yeah there is records in db news?
Last edited by Jamie_Garland; Jun 12th, 2015 at 11:24 AM.
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
-
Jun 12th, 2015, 11:37 AM
#6
Re: php help display news table records
Originally Posted by Jamie_Garland
Okay, I have been trying to figure out where my magnifying glass is, inorder to view that tiny image you attached!
Try accessing this url: http://www.yansumkune.com/?id=26
Is it showing the content now?
The problem was, in your code you have this line:
Code:
$page_id = $_GET['id'];
What it means is that, it will take the "id" parameter that you pass in the URL and is assigning to the variable named $page_id
And then you are doing the sql query using it:
Code:
$page_id = $_GET['id'];
$select_query = "select * from news where post_id='$page_id'";
Hope you understood it now. I would really suggest to do some more reading using some tutorials for PHP.
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Jun 12th, 2015, 02:14 PM
#7
Thread Starter
Frenzied Member
Re: php help display news table records
how would i get it to show the newest record only?.
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
-
Jun 12th, 2015, 02:22 PM
#8
Re: php help display news table records
Originally Posted by Jamie_Garland
how would i get it to show the newest record only?.
It would be something like this:
Code:
<?php include('styles/top.php'); ?>
<div id="left">
<?php
include("includes/connect.php");
$select_query = "SELECT * FROM news ORDER BY post_id DESC LIMIT 1";
$run_query = mysql_query($select_query);
$row=mysql_fetch_array($run_query)
$post_id = $row['post_id'];
$post_title = $row['post_title'];
$post_date = $row['post_date'];
$post_author = $row['post_author'];
$post_image = $row['post_image'];
$post_content =$row['post_content'];
?>
<h2>
<a href="pages.php?id=<?php echo $post_id; ?>">
<?php echo $post_title; ?>
</a>
</h2>
<p align="left">Published on: <b><?php echo $post_date; ?></b></p>
<p align="right">Posted by: <b><?php echo $post_author; ?></b></p>
<center><img src="images/<?php echo $post_image; ?>" width="500" height="300" /></center>
<p align="justify"><?php echo $post_content; ?></p>
</div>
<?php include('styles/bottom.php'); ?>
It's untested code. What we are doing is, we select the most recent single post. Because in query, we are selecting the rows in DESCENDING order of post_id
And the "LIMIT 1" will return only one single row. So you don't need the loop.
Just try fiddling with the code. And also, read more about SQL queries, PHP, etc.
W3schools has simple tutorials for PHP and SQL. Take a look at it.
I won't be answering further doubts of you until you read those tutorials and grasp some knowledge from it.
If my post was helpful to you, then express your gratitude using Rate this Post.
And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet
Social Group: VBForums - Developers from India
Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...
-
Jun 12th, 2015, 02:26 PM
#9
Thread Starter
Frenzied Member
Re: php help display news table records
i resolved this part.
I was wondering one last thing how do i make sure that there is a pic if not it dosent show it and if there is an image then it displays it this is the updated code.
Code:
<?php
include("includes/connect.php");
$select_posts = "select * from news order by 1 DESC LIMIT 1";
$run_posts = mysql_query($select_posts);
while($row=mysql_fetch_array($run_posts)){
$post_id = $row['post_id'];
$post_title = $row['post_title'];
$post_date = $row['post_date'];
$post_author = $row['post_author'];
$post_image = $row['post_image'];
$post_content = substr($row['post_content'],0,200);
?>
<h2>
<a href="pages.php?id=<?php echo $post_id; ?>">
<?php echo $post_title; ?>
</a>
</h2>
<p align="left">Published on: <b><?php echo $post_date; ?></b></p>
<p align="right">Posted by: <b><?php echo $post_author; ?></b></p>
<center><img src="news_pics/<?php echo $post_image; ?>" width="500" height="300" /></center>
<p align="justify"><?php echo $post_content; ?></p>
<p align="right"><a href="pages.php?id=<?php echo $post_id; ?>">Read More</a></p>
<hr>
<?php } ?>
come back and mark your original post as resoved if your problem is fixed
Jamie Garland
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|