Jump to content


Photo

How to insert html/javascript within php code


  • Please log in to reply
4 replies to this topic

#1 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 22 July 2006 - 06:07 PM

Can anyone please help me insert this line of html and javascript into my php code?

I have a radio button which when clicked will open delete_news.php
I want to put that in the php code so every record will have the radio button next to it so it can be deleted.

<input style="border:none;" type="radio" name="loc" onClick="go('index.php?page=delete_news');">

while($code = mysql_fetch_object($q)) { 
     echo("[b]<h3>[/b]".$code->title."</h3><BR>");}

I would like the HTML to replace the <h3> but becuase the HTML has " in it i'm not sure how to insert it
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 22 July 2006 - 06:18 PM

escape the quotes (\") or do this:
while($code = mysql_fetch_object($q)) {
     echo '<input style="border:none;" type="radio" name="loc" onClick="go(\'index.php?page=delete_news\');">' . $code->title . "<br />\n";


#3 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 22 July 2006 - 08:59 PM

I did what you mentioned but I am getting an error.  It says Parse error: syntax error, unexpected '>' in ........on line 47


line 47 is the line i changed

Here is the entire script
<fieldset>
<? 
//REMEMBER TO CONNECT TO DATABASE! 

include_once("../includes/connection.php");
    @mysql_connect($host, $user, $password) or die("ERROR--CAN'T CONNECT TO SERVER"); 
    @mysql_select_db($database) or die("ERROR--CAN'T CONNECT TO DB"); 
//**EDIT TO YOUR TABLE NAME, ECT. 

$t = mysql_query("SELECT * FROM `news`"); 
  if(!$t) die(mysql_error()); 
    
$a                = mysql_fetch_object($t); 
$total_items      = mysql_num_rows($t); 
$limit            = $_GET['limit']; 
$type             = $_GET['type']; 
$page             = $_GET['pagenum']; 

//set default if: $limit is empty, non numerical, less than 2, greater than 50 
if((!$limit)  || (is_numeric($limit) == false) || ($limit < 2) || ($limit > 50)) { 
     $limit = 2; //default 
} 
//set default if: $page is empty, non numerical, less than zero, greater than total available 
if((!$page) || (is_numeric($page) == false) || ($page < 0) || ($page > $total_items)) { 
      $page = 1; //default 
} 

//calcuate total pages 
$total_pages     = ceil($total_items / $limit); 
$set_limit          = $page * $limit - ($limit); 

//query: **EDIT TO YOUR TABLE NAME, ECT. 

$q = mysql_query("SELECT * FROM `news` LIMIT $set_limit, $limit"); 
  if(!$q) die(mysql_error()); 
     $err = mysql_num_rows($q); 
       if($err == 0) die("No matches met your criteria."); 

//Results per page: **EDIT LINK PATH** 
echo("   
<a href=?page=delete_news&limit=10&amp;pagenum=1></a> 
<a href=?page=delete_news&limit=25&amp;pagenum=1></a> 
<a href=?page=delete_news&limit=50&amp;pagenum=1></a>"); 

//show data matching query: 
while($code = mysql_fetch_object($q)) { 
     echo("<input style=\"border:none;\" type=\"radio\" name=\"loc\" onClick=\"go('index.php?page=deletenews');\">\".$code->title."<br>");
      
} 

$id = urlencode($id); //makes browser friendly 

//prev. page: **EDIT LINK PATH** 

$prev_page = $page - 1; 

if($prev_page >= 1) { 
  echo("<input style=\"border:none;\" type=\"radio\" name=\"loc\" onClick=\"go('index.php?page=deletenews');\">\".$code->title."<br>"); 
} 

//Display middle pages: **EDIT LINK PATH** 

for($a = 1; $a <= $total_pages; $a++) 
{ 
   if($a == $page) { 
      echo("<b> $a</b> | "); //no link 
     } else { 
  echo("  <a href=?page=delete_news&limit=$limit&amp;pagenum=$a> $a </a> | "); 
     } 
} 

//next page: **EDIT THIS LINK PATH** 

$next_page = $page + 1; 
if($next_page <= $total_pages) { 
   echo("<a href=?page=delete_news&limit=$limit&amp;pagenum=$next_page><b>Next</b></a> &gt; &gt;"); 
} 

//all done 
?>
</fieldset>

If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still

#4 corbin

corbin
  • Staff Alumni
  • Advanced Member
  • 8,129 posts

Posted 22 July 2006 - 09:05 PM

line 47... that would be:

echo("<input style=\"border:none;\" type=\"radio\" name=\"loc\" onClick=\"go('index.php?page=deletenews');\">\".$code->title."<br>");
?

echo "<inpput style=\border:none;\" type=\"radio\" name=\"loc\" onClick=\"go('index.php?page=deletenews');\">" . $code->title . "<br>";

should work.  It seems to me that you didnt need to escape the " around );\">\".$code
Why doesn't anyone ever say hi, hey, or whad up world?

#5 AdRock

AdRock
  • Members
  • PipPipPip
  • Advanced Member
  • 911 posts

Posted 22 July 2006 - 11:03 PM

Nope.....still didn't work.

in the same script that I use on another page, I have
echo("<h3>".$code->title."</h3><BR>");
on line 47 and it works perfectly except all that it does is display each of the records.
As soon as I add the other code it comes up with the error and i think it's referring to .$code->title.

Is there another way I can perform the query to display all the records with a radio button
If your topic has been solved, please mark the topic as SOLVED.

This helps others from identifying which topics need help still




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users