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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    Regular Coder
    Join Date
    Sep 2008
    Posts
    705
    Thanks
    8
    Thanked 17 Times in 16 Posts

    Php output as table

    Hello I need to combine this table with my php form:

    Basicly when someone registers the html table will be updated with another row

    Here is the PHP:

    PHP Code:

    <?php

    require("inc/config.php");
    if (isset(
    $_POST['del'])) 
    {

        for (
    $count 0;$count<count($_POST[delchk]);$count++)
       {
               
    $delete $_POST[delchk][$count];
               
    $query "DELETE FROM persons WHERE id = '$delete'";
               
    $result mysql_query($query);
               if (!
    $result
       {
                die(
    "Error deleting persons! Query: $query<br />Error: ".mysql_error());
            }
        }
    }
    $result mysql_query("SELECT * FROM persons");

    // Check how many rows it found
    if(mysql_num_rows($result) > 0){
    echo 
    "<input type='button' onclick='checkall(document.myform.delchk);' value='Select All'>";
    echo 
    "<input type='button' onclick='uncheckall(document.myform.delchk);' value='UnSelect All'>";
    echo 
    "<hr>";
    echo 
    "<form name = 'myform' action='' method='post'>";
    while(
    $row mysql_fetch_array($result))
      {
      echo 
    "First Name: " $row['FirstName'] . "";
      echo 
    "<br>";
      echo 
    "Last Name: " $row['LastName'] . "";
      echo 
    "<br>";
      echo 
    "<a target=frame2 href='" ."profile.php?user1="$row['FirstName'] ."'>Profile</a>"
      echo 
    "<br>"
      echo 
    "Date: " $row['AddedDate'] . "";
      echo 
    "<br>";
      echo 
    "IP Address: " $row['Ip'] . "";
      echo 
    "<br>";
      echo 
    'Select to delete: <input type="checkbox" id="delchk" name="delchk[]" value="'.$row['id'].'" />';  
      echo 
    "<br>";
      echo 
    "***********************************************";
      echo 
    "<br>";
      }
    echo 
    "<hr>";
    echo 
    "<input type='submit' name = 'del' value='Delete Selected'></form>";
    }

    else{
    // No rows were found ...
    echo 'No one has yet to register.'
    }

    mysql_close($con);
    ?>
    Here is the html table:
    Code:
    <table id="mytable">
    <thead>
    
    	<tr>
    
    		<th scope="col">Delete?</th>
    		<th scope="col">First Name</th>
    		<th scope="col">Last Name</th>
    		<th scope="col">Profile</th>
    		<th scope="col">Date</th>
    		<th scope="col">IP Address</th>
    
    	</tr>
    </thead>
    <tbody>
    
    	<tr>
    		<td>CheckBox</td>
    		<td>John</td>
    		<td>Mclan</td>
    		<td>Profile</td>
    		<td>August 25 2009</td>
    		<td>90.209.15.233</td>
    
    	</tr>
    </tbody>
    
    </table>
    Basicly when someone registers it adds this as another row.
    Code:
    	<tr>
    		<td>CheckBox</td>
    		<td>John</td>
    		<td>Mclan</td>
    		<td>Profile</td>
    		<td>August 25 2009</td>
    		<td>90.209.15.233</td>
    
    	</tr>
    Can someone help me out??

  • #2
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    You mean that you would like a new header row to be added with each info row?

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #3
    Regular Coder
    Join Date
    Sep 2008
    Posts
    705
    Thanks
    8
    Thanked 17 Times in 16 Posts
    No just a row with the clients information.

    Like a new row with 6 cells with each one containing a separate piece of the users information.

    I tried it myself but it didn't work.

    PHP Code:

    <?php

    require("inc/config.php");
    if (isset(
    $_POST['del'])) 
    {

        for (
    $count 0;$count<count($_POST[delchk]);$count++)
       {
               
    $delete $_POST[delchk][$count];
               
    $query "DELETE FROM persons WHERE id = '$delete'";
               
    $result mysql_query($query);
               if (!
    $result
       {
                die(
    "Error deleting persons! Query: $query<br />Error: ".mysql_error());
            }
        }
    }
    $result mysql_query("SELECT * FROM persons");

    // Check how many rows it found
    if(mysql_num_rows($result) > 0){
    echo 
    "<table id="mytable">
    <thead>

        <tr>
            <th scope="
    col">Delete?</th>
            <th scope="
    col">First Name</th>
            <th scope="
    col">Last Name</th>
            <th scope="
    col">Profile</th>
            <th scope="
    col">Date</th>
            <th scope="
    col">IP Address</th>
        </tr>
    </thead>
    <tbody>
    </tr>"
    ;

    echo 
    "<input type='button' onclick='checkall(document.myform.delchk);' value='Select All'>";
    echo 
    "<input type='button' onclick='uncheckall(document.myform.delchk);' value='UnSelect All'>";
    echo 
    "<hr>";
    echo 
    "<form name = 'myform' action='' method='post'>";
    while(
    $row mysql_fetch_array($result))
      {
      echo 
    "<td>First Name: " $row['FirstName'] . "</td>";
      echo 
    "<br>";
      echo 
    "<td>Last Name: " $row['LastName'] . "</td>";
      echo 
    "<br>";
      echo 
    "<td><a target=frame2 href='" ."profile.php?user1="$row['FirstName'] ."'>Check HighScores</a></td>"
      echo 
    "<br>"
      echo 
    "<td>Date: " $row['AddedDate'] . "</td>";
      echo 
    "<br>";
      echo 
    "<td>IP Address: " $row['Ip'] . "</td>";
      echo 
    "<br>";
      echo 
    'Select to delete: <input type="checkbox" id="delchk" name="delchk[]" value="'.$row['id'].'" />';  
      echo 
    "<br>";
      echo 
    "***********************************************";
      echo 
    "<br>";
      }
    echo 
    "<hr>";
    echo 
    "</tr>";
    echo 
    "</tbody>";
    echo 
    "</tbody>";
    echo 
    "<input type='submit' name = 'del' value='Delete Selected'></form>";

    }

    else{
    // No rows were found ...
    echo 'No one has yet registered.'
    }

    mysql_close($con);
    ?>
    Example--
    Before someone signs up:


    After another person signs up:

    (Basically adding another row)
    Last edited by bucket; 08-25-2009 at 09:01 PM.

  • #4
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Basicly when someone registers it adds this as another row.
    So when you wrote this did you mean that's what happens NOW or that's what you'd like to happen?

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #5
    Regular Coder
    Join Date
    Sep 2008
    Posts
    705
    Thanks
    8
    Thanked 17 Times in 16 Posts
    Yes, I would like another row to show up. I made a picture In my last post.

    Example--
    Before someone signs up:


    After another person signs up:

    (Basically adding another row)

    It shows what I would like to happen but cant figure out why the page shows up blank...

  • #6
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Code:
    <table id="mytable">
    <thead>
    
        <tr>
            <th scope="col">Delete?</th>
            <th scope="col">First Name</th>
            <th scope="col">Last Name</th>
            <th scope="col">Profile</th>
            <th scope="col">Date</th>
            <th scope="col">IP Address</th>
        </tr>
    </thead>
    <tbody>
    </tr>";
    You need to use \ to escape every " in that part (except for the very first and very last). Each time the script encounters a " it switches out of string mode and into php mode, which you don't want. Do you have error reporting turned off?

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #7
    Regular Coder
    Join Date
    Sep 2008
    Posts
    705
    Thanks
    8
    Thanked 17 Times in 16 Posts
    I dont know if I have error turned off. Can you post a working version of it?

    And also where would I add \ too?

  • #8
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    1. Add this line: error_reporting(E_ALL); to the top of the code (inside the <?php of course)

    2. the backslash is an 'escape' character. What this means is that you place it in front of a character which has a special meaning, but you want the code to ignore, such as " or $.

    So, to escape the code, place a backslash ( \ ) in front of every " you have in that block of code.

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #9
    Regular Coder
    Join Date
    Sep 2008
    Posts
    705
    Thanks
    8
    Thanked 17 Times in 16 Posts
    Its not showing errors...
    Even tho I added it.

    Can you show me where to put the \ in the code?

    PHP Code:
    <?php
    error_reporting
    (E_ALL); 
    require(
    "inc/config.php");
    if (isset(
    $_POST['del'])) 
    {

        for (
    $count 0;$count<count($_POST[delchk]);$count++)
       {
               
    $delete $_POST[delchk][$count];
               
    $query "DELETE FROM persons WHERE id = '$delete'";
               
    $result mysql_query($query);
               if (!
    $result
       {
                die(
    "Error deleting persons! Query: $query<br />Error: ".mysql_error());
            }
        }
    }
    $result mysql_query("SELECT * FROM persons");

    // Check how many rows it found
    if(mysql_num_rows($result) > 0){
    echo 
    "<table id="mytable">
    <thead>

        <tr>
            <th scope="
    col">Delete?</th>
            <th scope="
    col">First Name</th>
            <th scope="
    col">Last Name</th>
            <th scope="
    col">Profile</th>
            <th scope="
    col">Date</th>
            <th scope="
    col">IP Address</th>
        </tr>
    </thead>
    <tbody>
    </tr>"
    ;

    echo 
    "<input type='button' onclick='checkall(document.myform.delchk);' value='Select All'>";
    echo 
    "<input type='button' onclick='uncheckall(document.myform.delchk);' value='UnSelect All'>";
    echo 
    "<hr>";
    echo 
    "<form name = 'myform' action='' method='post'>";
    while(
    $row mysql_fetch_array($result))
      {
      echo 
    "<td>First Name: " $row['FirstName'] . "</td>";
      echo 
    "<br>";
      echo 
    "<td>Last Name: " $row['LastName'] . "</td>";
      echo 
    "<br>";
      echo 
    "<td><a target=frame2 href='" ."profile.php?user1="$row['FirstName'] ."'>Check HighScores</a></td>"
      echo 
    "<br>"
      echo 
    "<td>Date: " $row['AddedDate'] . "</td>";
      echo 
    "<br>";
      echo 
    "<td>IP Address: " $row['Ip'] . "</td>";
      echo 
    "<br>";
      echo 
    'Select to delete: <input type="checkbox" id="delchk" name="delchk[]" value="'.$row['id'].'" />';  
      echo 
    "<br>";
      echo 
    "***********************************************";
      echo 
    "<br>";
      }
    echo 
    "<hr>";
    echo 
    "</tr>";
    echo 
    "</tbody>";
    echo 
    "</tbody>";
    echo 
    "<input type='submit' name = 'del' value='Delete Selected'></form>";

    }

    else{
    // No rows were found ...
    echo 'No one has yet registered.'
    }

    mysql_close($con);
    ?>

  • #10
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    OK Change

    PHP Code:
    echo "<table id="mytable">
    <thead>

        <tr>
            <th scope="
    col">Delete?</th>
            <th scope="
    col">First Name</th>
            <th scope="
    col">Last Name</th>
            <th scope="
    col">Profile</th>
            <th scope="
    col">Date</th>
            <th scope="
    col">IP Address</th>
        </tr>
    </thead>
    <tbody>
    </tr>"

    to

    PHP Code:
    echo "<table id=\"mytable\">
    <thead>

        <tr>
            <th scope=\"col\">Delete?</th>
            <th scope=\"col\">First Name</th>
            <th scope=\"col\">Last Name</th>
            <th scope=\"col\">Profile</th>
            <th scope=\"col\">Date</th>
            <th scope=\"col\">IP Address</th>
        </tr>
    </thead>
    <tbody>
    </tr>"

    Then tell me what happens

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #11
    Regular Coder
    Join Date
    Sep 2008
    Posts
    705
    Thanks
    8
    Thanked 17 Times in 16 Posts
    I think I have fully fixed it. It is now showing up:

    PHP Code:
    <?php
    error_reporting
    (E_ALL);

    require(
    "inc/config.php");
    if (isset(
    $_POST['del'])) 
    {

        for (
    $count 0;$count<count($_POST[delchk]);$count++)
       {
               
    $delete $_POST[delchk][$count];
               
    $query "DELETE FROM persons WHERE id = '$delete'";
               
    $result mysql_query($query);
               if (!
    $result
       {
                die(
    "Error deleting persons! Query: $query<br />Error: ".mysql_error());
            }
        }
    }
    $result mysql_query("SELECT * FROM persons");

    // Check how many rows it found
    if(mysql_num_rows($result) > 0){
    echo 
    "<table id=\"mytable\">
    <thead>

        <tr>
            <th scope=\"col\">Delete?</th>
            <th scope=\"col\">First Name</th>
            <th scope=\"col\">Last Name</th>
            <th scope=\"col\">Profile</th>
            <th scope=\"col\">Date</th>
            <th scope=\"col\">IP Address</th>
        </tr>
    </thead>
    <tbody>"



    echo 
    "<form name = 'myform' action='' method='post'>";
    while(
    $row mysql_fetch_array($result))
      {
      echo 
    "<tr>";
      echo 
    "<td>" $row['FirstName'] . "</td>";
      echo 
    "<td>" $row['LastName'] . "</td>";
      echo 
    "<td><a target=frame2 href='" ."http://hiscore.runescape.com/hiscorepersonal.ws?user1="$row['FirstName'] ."'>Check HighScores</a></td>"
      echo 
    "<td>" $row['AddedDate'] . "</td>";
      echo 
    "<td>" $row['Ip'] . "</td>";
      echo 
    '<td><input type="checkbox" id="delchk" name="delchk[]" value="'.$row['id'].'" /></td>';  
      echo 
    "</tr>";
      }
    echo 
    "</tbody>";
    echo 
    "</table>";
    echo 
    "<input type='submit' name = 'del' value='Delete Selected'></form>";
    echo 
    "<input type='button' onclick='checkall(document.myform.delchk);' value='Select All'>";
    echo 
    "<input type='button' onclick='uncheckall(document.myform.delchk);' value='UnSelect All'>";

    }

    else{
    // No rows were found ...
    echo 'Your account list is clear. Please wait for people to login.'
    }

    mysql_close($con);
    ?>
    But the only thing is, how do I make certain cells smaller than others, like the width.

  • #12
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    You can do that either by using the width attribute in each <td>

    <td width="150">

    Or through CSS:

    .narrow
    {
    width:150px;
    }

    <td class="narrow">

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #13
    Regular Coder
    Join Date
    Sep 2008
    Posts
    705
    Thanks
    8
    Thanked 17 Times in 16 Posts
    Thanks.

    This is the finished code:

    Please comment on what you think should be changed, is unneeded, or what should should be added.
    PHP Code:
    <?php
    error_reporting
    (E_ALL);

    require(
    "inc/config.php");
    if (isset(
    $_POST['del'])) 
    {

        for (
    $count 0;$count<count($_POST[delchk]);$count++)
       {
               
    $delete $_POST[delchk][$count];
               
    $query "DELETE FROM persons WHERE id = '$delete'";
               
    $result mysql_query($query);
               if (!
    $result
       {
                die(
    "Error deleting persons! Query: $query<br />Error: ".mysql_error());
            }
        }
    }
    $result mysql_query("SELECT * FROM persons");

    // Check how many rows it found
    if(mysql_num_rows($result) > 0){
    echo 
    "<table id=\"mytable\">
    <thead>

        <tr>
            <th align=\"center\" scope=\"col\">Delete?</th>
            <th align=\"center\" scope=\"col\">First Name</th>
            <th align=\"center\" scope=\"col\">Last Name</th>
            <th align=\"center\" scope=\"col\">Profile</th>
            <th align=\"center\" scope=\"col\">Date</th>
            <th align=\"center\" scope=\"col\">IP Address</th>
        </tr>
    </thead>
    <tbody>"



    echo 
    "<form name = 'myform' action='' method='post'>";
    while(
    $row mysql_fetch_array($result))
      {
      echo 
    "<tr align=\"center\">";
      echo 
    '<td><input type="checkbox" id="delchk" name="delchk[]" value="'.$row['id'].'" /></td>';  
      echo 
    "<td>" $row['FirstName'] . "</td>";
      echo 
    "<td>" $row['LastName'] . "</td>";
      echo 
    "<td><a target=frame2 href='" ."profile.php?user1="$row['FirstName'] ."'>Check Profile</a></td>"
      echo 
    "<td>" $row['AddedDate'] . "</td>";
      echo 
    "<td>" $row['Ip'] . "</td>";
      echo 
    "</tr>";
      }
    echo 
    "</tbody>";
    echo 
    "</table>";
    echo 
    "<hr>";
    echo 
    "<input type='submit' name = 'del' value='Delete Selected'></form>";
    echo 
    "<input type='button' onclick='checkall(document.myform.delchk);' value='Select All'>";
    echo 
    "<input type='button' onclick='uncheckall(document.myform.delchk);' value='UnSelect All'>";

    }

    else{
    // No rows were found ...
    echo 'No registered members.'
    }

    mysql_close($con);
    ?>

  • #14
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    It looks good, I would just say make sure you are checking the POST values, so that someone couldn't mess with your script.

    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #15
    Regular Coder
    Join Date
    Sep 2008
    Posts
    705
    Thanks
    8
    Thanked 17 Times in 16 Posts
    You mean so someone cant click register2.php like 6 times and create blank or multiple accounts?


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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