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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts

    handling class and function

    hi

    i have a script for displaying the records from mysql table along with checkboxes to delete the multiple records from table.what i want is i want to put the code inside one class and one function.that's all.but when i put the code in class & function the record is not deleting but when i remove the class & function the record is deleting.any of your help will be appreciated.
    here is my code
    view.html.php
    PHP Code:
    <?php 
    //class viewclients_html 
    //{ 
    //function viewclients() 
    //{ 
    include 'db.php'
    mysql_connect($host,$username,$password); 
    mysql_select_db($db) or die("Unable to select database"); 

    $sql="SELECT * FROM host ORDER BY date DESC"
    $result=mysql_query($sql); 

    $count=mysql_num_rows($result); 

    ?> 
    <center><table width="700" border="0" cellspacing="1" cellpadding="0"> 
    <tr> 
    <td><font color="navy"><form name="form1" method="post" action=""><br><center><b> 
    <u><font color="magenta">CLIENTS</font></u></b></center><br><br> 
    <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> 
    <tr> 

    <td bgcolor="lightgreen" align="center"><font color="navy">#</font></td> 
    <td bgcolor="lightgreen" align="center"><font color="navy"><strong>Id</strong></font></td> 
    <td bgcolor="lightgreen" align="center"><font color="navy"><strong>Name</strong></font></td> 
    <td bgcolor="lightgreen" align="center"><font color="navy"><strong>Email</strong></font></td> 
    <td bgcolor="lightgreen" align="center"><font color="navy"><strong>Phone</strong></font></td> 
    <td bgcolor="lightgreen" align="center"><font color="navy"><strong>Country</strong></font></td> 
    <td bgcolor="lightgreen" align="center"><font color="navy"><strong>City</strong></font></td> 
    <td bgcolor="lightgreen" align="center"><font color="navy"><strong>Message</strong></font></td> 
    <td bgcolor="lightgreen" align="center"><font color="navy"><strong>Date</strong></font></td> 

    </tr> 
    <?php 
    while($rows=mysql_fetch_array($result)){ 
    ?> 
    <font color="navy"> 
    <tr  class="odd" onmouseover="over(this);" onmouseout="out(this);"> 
    <td align="center"><font color="navy"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></font></td> 
    <td><font color="navy"><? echo $rows['id']; ?></font></td> 


    <td><font color="navy"><? echo $rows['name']; ?></font></td> 
    <td><font color="navy"><? echo $rows['email']; ?></font></td> 
    <td><font color="navy"><? echo $rows['phone']; ?></font></td> 
    <td><font color="navy"><? echo $rows['country']; ?></font></td> 
    <td><font color="navy"><? echo $rows['city']; ?></font></td> 
    <td><font color="navy"><? echo $rows['message']; ?></font></td> 
    <td><font color="navy"><? echo $rows['date']; ?></font></td> 
    </tr></font> 
    <?php 

    ?> 
    <tr> 
    <td colspan="5" align="center" ><input name="delete" type="submit" id="delete" value="Delete"></font></td> 
    </tr></table></center> 
    <? 
    // Check if delete button active, start this 
    if($delete){ 
    for(
    $i=0;$i<$count;$i++){ 
    $del_id $checkbox[$i]; 
    $sql "DELETE FROM host WHERE id='$del_id'"
    $result mysql_query($sql); 


    // if successful redirect to checkdelete1.php 
    if($result){ 
    echo 
    "<meta http-equiv=\"refresh\" content=\"0;URL=viewclients.php\">"


    mysql_close(); 
    //}} class & function close 
    ?> 
    </table> 
    </form> 
    </font></td> 
    </tr> 
    </table></center> 
    <style type="text/css"> 
    <!-- 
    tr.odd{background-color:white;} 
    tr.even{background-color:red;} 
    --> 
    </style> 
    <script language="JavaScript" type="text/javascript"> 
    <!-- 
    function over(row) 

        row.oldBackgroundColor = row.style.backgroundColor; 
        row.style.backgroundColor = 'pink'; 

    function out(row) 

        row.style.backgroundColor = row.oldBackgroundColor; 

    //--> 
    </script>
    iam accessing the function in another script as follows
    view.php
    <?php
    require_once( $mainframe->getPath( 'front_html' ) );

    viewclients_HTML::viewclients();
    ?>

  • #2
    New Coder
    Join Date
    Jul 2005
    Posts
    81
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try it like this

    PHP Code:
    <?php 
    class viewclients_html 

    function 
    viewclients() 

    include 
    'db.php'
    mysql_connect($host,$username,$password); 
    mysql_select_db($db) or die("Unable to select database"); 

    $sql="SELECT * FROM host ORDER BY date DESC"
    $result=mysql_query($sql); 

    $count=mysql_num_rows($result); 

    ?> 
    <center><table width="700" border="0" cellspacing="1" cellpadding="0"> 
    <tr> 
    <td><font color="navy"><form name="form1" method="post" action=""><br><center><b> 
    <u><font color="magenta">CLIENTS</font></u></b></center><br><br> 
    <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> 
    <tr> 

    <td bgcolor="lightgreen" align="center"><font color="navy">#</font></td> 
    <td bgcolor="lightgreen" align="center"><font color="navy"><strong>Id</strong></font></td> 
    <td bgcolor="lightgreen" align="center"><font color="navy"><strong>Name</strong></font></td> 
    <td bgcolor="lightgreen" align="center"><font color="navy"><strong>Email</strong></font></td> 
    <td bgcolor="lightgreen" align="center"><font color="navy"><strong>Phone</strong></font></td> 
    <td bgcolor="lightgreen" align="center"><font color="navy"><strong>Country</strong></font></td> 
    <td bgcolor="lightgreen" align="center"><font color="navy"><strong>City</strong></font></td> 
    <td bgcolor="lightgreen" align="center"><font color="navy"><strong>Message</strong></font></td> 
    <td bgcolor="lightgreen" align="center"><font color="navy"><strong>Date</strong></font></td> 

    </tr> 
    <?php 
    while($rows=mysql_fetch_array($result)){ 
    ?> 
    <font color="navy"> 
    <tr  class="odd" onmouseover="over(this);" onmouseout="out(this);"> 
    <td align="center"><font color="navy"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></font></td> 
    <td><font color="navy"><? echo $rows['id']; ?></font></td> 


    <td><font color="navy"><? echo $rows['name']; ?></font></td> 
    <td><font color="navy"><? echo $rows['email']; ?></font></td> 
    <td><font color="navy"><? echo $rows['phone']; ?></font></td> 
    <td><font color="navy"><? echo $rows['country']; ?></font></td> 
    <td><font color="navy"><? echo $rows['city']; ?></font></td> 
    <td><font color="navy"><? echo $rows['message']; ?></font></td> 
    <td><font color="navy"><? echo $rows['date']; ?></font></td> 
    </tr></font> 
    <?php 

    ?> 
    <tr> 
    <td colspan="5" align="center" ><input name="delete" type="submit" id="delete" value="Delete"></font></td> 
    </tr></table></center> 
    <? 
    // Check if delete button active, start this 
    if($delete){ 
    for(
    $i=0;$i<$count;$i++){ 
    $del_id $checkbox[$i]; 
    $sql "DELETE FROM host WHERE id='$del_id'"
    $result mysql_query($sql); 


    // if successful redirect to checkdelete1.php 
    if($result){ 
    echo 
    "<meta http-equiv=\"refresh\" content=\"0;URL=viewclients.php\">"


    mysql_close(); 
    //}} class & function close 
    ?> 
    </table> 
    </form> 
    </font></td> 
    </tr> 
    </table></center> 
    <style type="text/css"> 
    <!-- 
    tr.odd{background-color:white;} 
    tr.even{background-color:red;} 
    --> 
    </style> 
    <script language="JavaScript" type="text/javascript"> 
    <!-- 
    function over(row) 

        row.oldBackgroundColor = row.style.backgroundColor; 
        row.style.backgroundColor = 'pink'; 

    function out(row) 

        row.style.backgroundColor = row.oldBackgroundColor; 

    //--> 
    </script>
    <?

    }

    }
    ?>
    And you could call it like

    PHP Code:
    <?php
    require_once( $mainframe->getPath'front_html' ) );
    $cl = new(viewclients_html);
    $cl->viewclients();
    ?>
    If you can not find a decision, maybe you have to try to change a problem

    http://www.gunman.co.nr
    http://bglinux.org

  • #3
    Regular Coder
    Join Date
    Aug 2006
    Posts
    133
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hi gunman,


    thanks for your reply.i tried your code but the record is not deleted.any more suggestions you have, please post it.


    thanks
    mrjameer


  •  

    Posting Permissions

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