Jump to content

php URL Help


logicopinion

Recommended Posts

Hello EveryBody.

 

i am trying to print out couple of DATA from DB. here is code:

 

<?php

mysql_connect("localhost", "root", "") or die(mysql_error());

mysql_select_db("mynews") or die(mysql_error());

$query = "SELECT * FROM newsdb";

$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result))

{

 

print "<table cellpadding=0 cellspacing= width=100%>";

print "<tr><td>"; echo $row['date']; print "</td></tr>";

 

 

print "<tr><td>"; echo $row['title']; print "</td></td>";

 

print "<tr><td>"; echo "<a href=\"read_news.php?cid=$row['news']\">more...</a>"; print "</td></td>";

 

print "</table>";

 

}

 

?>

 

but the BOLD text you see above is an URL which must show Full Content of that News..

it gives me an error:

 

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\htdocs\mynews\read_news.php on line 26

 

what is wrong with that ? Please Help.

 

Thank You.

Link to comment
Share on other sites

Hello,

 

Replace your code

print "<tr><td>"; echo "<a href=\"read_news.php?cid=$row['news']\">more...[/url]"; print "</td></td>";

 

with the following..

print "<tr><td>"; 
echo "<a href='read_news.php?cid=".$row['news'] ."'>more...</a>"; 
print "</td></td>";

 

Hope this will solve your issue.

 

Regards,

Link to comment
Share on other sites

I always try to avoid having to escape " (double quotes) when printing / echoing html:

 

 

<?php

echo '<tr><td>'; 
echo '<a href="read_news.php?cid=' . $row['news'] . '">more...</a>';
echo '</td></td>';

?>

 

So if you are printing / echoing double quotes use single quotes to define the strings and the other way round.

Link to comment
Share on other sites

yes i have AUTO_INCREMENT primary key (id)

 

and now i replaced $row['news'] with $row['id'] and it does such thing when i press more button URL looks Like

 

http://localhost/mynews/read_news.php?cid=8

 

http://localhost/mynews/read_news.php?cid=9

 

 

etc...

 

 

but it does not print any data anyway. the page stays same.. should i add here something like

 

 

$cid= &$_REQUEST['cid'];

if (!file_exists($go.".php)) { include "body.php"; next;}

else

{ if (isset($cid) && $cid!='body')

{ include "$cid.".php"; }

 

else

{ include "body.php";  }}

Link to comment
Share on other sites

this is body.php CODE:

 

<?php

mysql_connect("localhost", "root", "") or die(mysql_error());

mysql_select_db("mynews") or die(mysql_error());

$query = "SELECT * FROM newsdb ORDER BY id DESC LIMIT 0, 30";

$result = mysql_query($query) or die(mysql_error());

print "<table cellpadding=0 cellspacing= width=100% width=700>";

while($row = mysql_fetch_array($result))

{

print "<tr><td bgcolor= #FFF8DC style=\"BORDER-BOTTOM:1px #1E90FF solid;\">"; echo $row['date']; print "</td></tr>";

print "<tr><td>"; echo $row['title']; print "<br><br>"; print "</td></td>";

print "<tr><td align=right>";

echo "<a href='read_news.php?id=".$row['id'] ."'>დაწვრილებით</a>";

print "<br><br>";

print "</td></td>";

}

print "</table>";

?>

 

and this is read_news.php CODE:

 

<?php

 

$id= &$_REQUEST['id'];

 

if (isset($id) && $id!='body')

{

 

echo "$id";

 

}

 

else

{

 

include "body.php";

 

}

 

?>

 

and everything works Fine.. when i press more button it goes to specified ID .. but instead of FULL TEXT it Prints ID

 

expl: 12

 

so i see i requested it to find if there is any id set and print it out but instead of and id i want to to PRINT out FULL TEXT wich is Stored in the same DB in a Column Named NEWS.. what should i do?

Link to comment
Share on other sites

Hello,

 

In 'read_news.php', instead of echoing id, get the related record for this id from the database and display that. So.. modify the code as per the comments below...

<?php

$id= &$_REQUEST['id'];
if (isset($id) && $id!='body')
{
// connect to the DB
// Get the records from table 'newsdb' where id = $id
// display 'news_details'
}
else
{
include "body.php";
}
?>

 

Hope this will solve your issue.

Regards,

Link to comment
Share on other sites

i am done man thanks a lot

 

this is code :

 


?php
$id= &$_REQUEST['id'];


if (isset($id) && $id!='body') 

{

mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("mynews") or die(mysql_error());
$query = "SELECT * FROM newsdb WHERE id='id'";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result))

{ echo $row['news']; }

} 

else
{ 

include "body.php";

}



?>


Link to comment
Share on other sites

and one more thing PLEASE.

 

i insert long text into DB and when php prints it out...

 

there is some text written but now Whole

 

for example i insert: wow, my script is working perfectly, but there is some lil error around

 

and when i desplay it it shows like this : wow, my script is working perfectly, bu?

 

i actually USE UTF-8 for my language (Georgian)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.