Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    84
    Thanks
    49
    Thanked 0 Times in 0 Posts

    how to insert sql data in an html table

    Hello All...

    I have this table that i made as a placeholder while designing my site...
    How would I insert sql data in the table data fields
    if I have selected this info using the SELECT function?

    Code:
    <h2>Activist Investor Conference</h2><br>
    <table width="500" border="0" cellpadding="5">
      <tr>
        <td>Calendar</td>
        <td>Outlook | Google | Apple iCal | Yahoo | MSN</td>
      </tr>
      <tr>
        <td>Share</td>
        <td>Linkedin | Facebook | Google+ | Twitter | Stocktwits</td>
      </tr>
      <tr>
        <td>Venue</td>
        <td>Waldorf Astoria</td>
      </tr>
      <tr>
        <td>Location</td>
        <td>123 Central Park Lane - New York NY 11298</td>
      </tr>
       <tr>
        <td>Rating</td>
        <td>*****</td>
      </tr>
     </table>

  • #2
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    See the answer I gave in one of your other posts. It's just a case of either formatting the HTML around it, or putting it in a templatable manner for the PHP to parse with the html.
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • Users who have thanked BluePanther for this post:

    jchrisphonte (02-01-2012)

  • #3
    New Coder
    Join Date
    Jan 2012
    Posts
    84
    Thanks
    49
    Thanked 0 Times in 0 Posts
    Hey Blue Panther,

    thank you for all your help on here - i looked back into your old post to me and i found the one where i learned about styling php with <div class=>

    I tried that on the table below yet the data doesnt pull with it... am i doing something wrong?

    Code:
    <?php
    $id = (int) $_GET['id'];
    
    require 'connect.inc.php';
    
    mysql_select_db("hedgevent");
    
    if ((int) $_GET['id']) $result = mysql_query('SELECT id, event, company, description, location, address, suite, city, state, zip, country, sdate, edate, time_from, time_until, contactname, email, phone, website  FROM calendar_event WHERE id = '.(int) $_GET['id']);
    
    if($row = mysql_fetch_array($result))
      if($query_row = mysql_fetch_assoc($result)){
    	  
      	$id= $query_row ['id'];
    	$event= $query_row ['event'];
    	$company= $query_row ['company'];
    	$description= $query_row ['description'];
    	$location= $query_row ['location'];
    	$address= $query_row ['address'];
    	$suite= $query_row ['suite'];
    	$city= $query_row ['city'];			  
    	$state= $query_row ['state'];
    	$zip= $query_row ['zip'];
     	$zip= $query_row ['country'];
    	$sdate= $query_row ['sdate'];
    	$edate= $query_row ['edate'];
    	$timef= $query_row ['time_from'];
    	$timeu= $query_row ['time_until'];
    	$contact= $query_row ['contactname'];
    	$email= $query_row ['email'];			  
    	$phone= $query_row ['phone'];
    	$website= $query_row ['website'];
     }
    ?>        
       
           
    <div id="container">
    	<div id="listing">	
    
        <h2><div class="event">'.$event.'</h2><br>
    <table width="500" border="0" cellpadding="5">
      <tr>
        <td>Calendar</td>
        <td>Outlook | Google | Apple iCal | Yahoo | MSN</td>
      </tr>
      <tr>
        <td>Share</td>
        <td>Linkedin | Facebook | Google+ | Twitter | Stocktwits</td>
      </tr>
      <tr>
        <td>Venue</td>
        <td>'.$location.'</td>
      </tr>
      <tr>
        <td>Location</td>
        <td>'.$address.' - '.$city.' '.$state.' '.$zip'</td>
      </tr>
       <tr>
        <td>Rating</td>
        <td>*****</td>
      </tr>
     </table>
    <br>
    <p>Details:</p> <br>
    <p>'.$description.'
    </p>

  • #4
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by jchrisphonte View Post
    Hey Blue Panther,

    thank you for all your help on here - i looked back into your old post to me and i found the one where i learned about styling php with <div class=>

    I tried that on the table below yet the data doesnt pull with it... am i doing something wrong?

    Code:
    <?php
    $id = (int) $_GET['id'];
    
    require 'connect.inc.php';
    
    mysql_select_db("hedgevent");
    
    if ((int) $_GET['id']) $result = mysql_query('SELECT id, event, company, description, location, address, suite, city, state, zip, country, sdate, edate, time_from, time_until, contactname, email, phone, website  FROM calendar_event WHERE id = '.(int) $_GET['id']);
    
    if($row = mysql_fetch_array($result))
      if($query_row = mysql_fetch_assoc($result)){
    	  
      	$id= $query_row ['id'];
    	$event= $query_row ['event'];
    	$company= $query_row ['company'];
    	$description= $query_row ['description'];
    	$location= $query_row ['location'];
    	$address= $query_row ['address'];
    	$suite= $query_row ['suite'];
    	$city= $query_row ['city'];			  
    	$state= $query_row ['state'];
    	$zip= $query_row ['zip'];
     	$zip= $query_row ['country'];
    	$sdate= $query_row ['sdate'];
    	$edate= $query_row ['edate'];
    	$timef= $query_row ['time_from'];
    	$timeu= $query_row ['time_until'];
    	$contact= $query_row ['contactname'];
    	$email= $query_row ['email'];			  
    	$phone= $query_row ['phone'];
    	$website= $query_row ['website'];
     }
    ?>        
       
           
    <div id="container">
    	<div id="listing">	
    
        <h2><div class="event">'.$event.'</h2><br>
    <table width="500" border="0" cellpadding="5">
      <tr>
        <td>Calendar</td>
        <td>Outlook | Google | Apple iCal | Yahoo | MSN</td>
      </tr>
      <tr>
        <td>Share</td>
        <td>Linkedin | Facebook | Google+ | Twitter | Stocktwits</td>
      </tr>
      <tr>
        <td>Venue</td>
        <td>'.$location.'</td>
      </tr>
      <tr>
        <td>Location</td>
        <td>'.$address.' - '.$city.' '.$state.' '.$zip'</td>
      </tr>
       <tr>
        <td>Rating</td>
        <td>*****</td>
      </tr>
     </table>
    <br>
    <p>Details:</p> <br>
    <p>'.$description.'
    </p>
    Use [PHP] tags instead of code tags .

    $query_row shouldn't have any spaces between the name and index. In other words, it should be $query_row['phone'] not $query_row ['phone']. Also, you can't just go in and out of html like that. They're two different things - HTML is output, PHP is the processor. PHP is executed server side, then once it's finished, all the output is sent to the client. You should be doing this:
    PHP Code:
    <?php
    $id 
    = (int) $_GET['id'];

    require 
    'connect.inc.php';

    mysql_select_db("hedgevent");

    $result mysql_query('SELECT id, event, company, description, location, address, suite, city, state, zip, country, sdate, edate, time_from, time_until, contactname, email, phone, website  FROM calendar_event WHERE id = '$id);

    if(
    $row mysql_fetch_array($result))
      if(
    $query_row mysql_fetch_assoc($result)){
          
          
    $id$query_row['id'];
        
    $event$query_row['event'];
        
    $company$query_row['company'];
        
    $description$query_row['description'];
        
    $location$query_row['location'];
        
    $address$query_row['address'];
        
    $suite$query_row['suite'];
        
    $city$query_row['city'];              
        
    $state$query_row['state'];
        
    $zip$query_row['zip'];
         
    $zip$query_row['country'];
        
    $sdate$query_row['sdate'];
        
    $edate$query_row['edate'];
        
    $timef$query_row['time_from'];
        
    $timeu$query_row['time_until'];
        
    $contact$query_row['contactname'];
        
    $email$query_row['email'];              
        
    $phone$query_row['phone'];
        
    $website$query_row['website'];
     }
    ?>        
       
           
    <div id="container">
        <div id="listing">    

        <h2><div class="event"><?php echo $event?></h2><br>
    <table width="500" border="0" cellpadding="5">
      <tr>
        <td>Calendar</td>
        <td>Outlook | Google | Apple iCal | Yahoo | MSN</td>
      </tr>
      <tr>
        <td>Share</td>
        <td>Linkedin | Facebook | Google+ | Twitter | Stocktwits</td>
      </tr>
      <tr>
        <td>Venue</td>
        <td><?php echo $location?></td>
      </tr>
      <tr>
        <td>Location</td>
        <td><?php echo $address.' - '.$city.' '.$state.' '.$zip?></td>
      </tr>
       <tr>
        <td>Rating</td>
        <td>*****</td>
      </tr>
     </table>
    <br>
    <p>Details:</p> <br>
    <p><?php echo $description?>
    </p>
    The . is PHP's concatenation operator. Should be used like this:
    PHP Code:
    $string 'foo'.'bar';
    echo 
    $string// foobar 
    You can break into PHP and HTML like above, using <?php and ?>, but it will be processed the exact same - PHP will prepare the output first, then send it. For multiple row results in the future, you should prepare the html inside the while loop. Not important for you just now though.

    Also, you would have noticed an error from PHP if you had error reporting turned on
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • Users who have thanked BluePanther for this post:

    jchrisphonte (02-01-2012)

  • #5
    New Coder
    Join Date
    Jan 2012
    Posts
    84
    Thanks
    49
    Thanked 0 Times in 0 Posts
    Great tips BP,

    getting an error with this though...

    Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\htdocs\eventdetails.php on line 67

    Here is what i have for line 67:

    PHP Code:
    $result mysql_query('SELECT id, event, company, description, location, address, suite, city, state, zip, country, sdate, edate, time_from, time_until, contactname, email, phone, website FROM calendar_event WHERE id = '$id); 
    says online i may be missing a bracket or semicolon??
    Last edited by jchrisphonte; 02-01-2012 at 07:00 AM.

  • #6
    New Coder
    Join Date
    Jan 2012
    Posts
    84
    Thanks
    49
    Thanked 0 Times in 0 Posts
    previous and following lines included here:

    PHP Code:

    mysql_select_db
    ("hedgevent"); 

    $result mysql_query('SELECT id, event, company, description, location, address, suite, city, state, zip, country, sdate, edate, time_from, time_until, contactname, email, phone, website FROM calendar_event WHERE id = '$id); 

    if(
    $row mysql_fetch_array($result)) 

  • #7
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by jchrisphonte View Post
    Great tips BP,

    getting an error with this though...

    Parse error: syntax error, unexpected T_VARIABLE in C:\xampp\htdocs\eventdetails.php on line 67

    Here is what i have for line 67:

    PHP Code:
    $result mysql_query('SELECT id, event, company, description, location, address, suite, city, state, zip, country, sdate, edate, time_from, time_until, contactname, email, phone, website FROM calendar_event WHERE id = '$id); 
    says online i may be missing a bracket or semicolon??
    It's exactly what the error says - it wasn't expecting one of the variables on line 67. mysql_query() takes a string parameter, the string being a query. So, to use variables in the query you either have to wrap the string in "'s (" will parse variables inside it, whereas ' will treat variables as literal strings) or use ' with the concatenation operator - .
    PHP Code:
    $var 'bar';
    $string "foo$var"// foobar
    $string 'foo'.$var// foobar 
    So, to summarise, you need to concatenate the id variable onto the query string using .$id
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •