0

Hello, I have done a PHP project and on my localhost it is working perfectly but when I uploaded it on my webspace the CMS part of my website did not work as it is supposed to.

The strange thing is that the client side of the website is working correctly not like the admin part of the website(CMS).

The error given is:Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/a5800815/public_html/draw/datagrid.php on line 48

The code for datagrid.php is:

<?php


        class datagrid
        {





            public $dataset;
            public $name;
            public $fields;
            public $altClass;
            public $itemID;
            public $oClass;
            //public $noClass;
            public $buffer;






            function __construct($name, $dataset)
            {
                $this->name = $name;
                $this->dataset = $dataset;

            }




            function datablind()
            {


             echo '<table name="'.$this->name.'"  id="'.$this->name.'" class="'.$this->altClass.'">';
               	echo "<tr>";
			foreach($this->fields as $field => $value) {
                        echo "<th>" . $field . "</th>";
                    }
		echo "</tr>";


             $count = 1;
            while($record = mysql_fetch_assoc($this->dataset))
            {

                /*if (isset($this->noClass['set']))
                {*/

                    $count=$count+1;
                    if (($count % 2)==0)
                    {
                          echo '<tr class="'.$this->altClass.'">';
                                foreach($record as $field => $value)
                                    {

                                        if (in_array($field, $this->fields))
                                        {
                                                /*if (in_array('image',$this->fields))
                                                {
                                                    echo '<td><img src="../uploads/' .$value . '"</td>';

                                                }
                                                else*/
                                                {
                                                     echo '<td>' . $value . '</td>';
                                                }
                                        }


                                }
                               echo '<td><a href="?id='. $record['ID'] .'">Select</a></td>';
                               echo '<td><a href="?updateid='. $record['ID'] .'">Update</a></td>';
                               echo '<td><a href="?deleteid='. $record['ID'] .'">Delete</a></td>';
                                echo "</tr>";

                    }
                    else
                    {
                         echo '<tr class="'.$this->oClass.'">';
                                foreach($record as $field => $value)
                                    {

                                        if (in_array($field, $this->fields))
                                        {
                                                /*if (in_array('image',array_keys($record)))
                                                {
                                                    echo '<td><img src="../uploads/' .$value . '"</td>';

                                                }
                                                else*/
                                                {
                                                     echo '<td>' . $value . '</td>';
                                                }



                                        }


                                    }
                               echo '<td><a href="?id='. $record['ID'] .'">Select</a></td>';
                               echo '<td><a href="?updateid='. $record['ID'] .'">Update</a></td>';
                               echo '<td><a href="?deleteid='. $record['ID'] .'">Delete</a></td>';
                                echo "</tr>";



                    }
                }




           echo "</table>";

		//$row = mysql_fetch_assoc($this->buffer);
                //print_r($row);





            }

            }


        ?>

Would someone be so kind to help me out this problem as I am new to PHP?

Thanks in advance Marius

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Stefano Mtangoo
0

your datagrid class is poorly designed and here is why:
1. You have mixed Database issues with non database
-Either make it fully database with all connections and queries in one class
2. You make mistake of adding html into class. Html should be in separate php class where you will be calling class methods. Here is small skeletal example. I have mixed DB functions and data getting but it is best to separate them

<?php
class DataClass{
    private $host="localhost";
    private $username="database_username";
    private $password = "password";
    private $db = "blog_database";
    private $conn; //shared connection by all class function via $this->conn
    
    public function __construct(){
       $this->conn = mysql_connect(.....);
       mysql_select_db(...); //use $this->db/conn
    }
    
    public function getBlogData($id){
        //get all the data using query
        //get array of blog data
        $array = mysql_fetch_assoc(....);//array of blog data
        return $array;
    }
    
    //other functions

}
?>


<html>
    <head>
    </head>
    
    <body>
        <div>
        <?php
            $blog_obj = new DataClass();        
            foreach($blog_obj->getBlogData($_POST['id']) as $heading=>$contents){
                echo "<h3>$heading</h3> $contents";
            }
        ?>
        </div>
    </body>

</html>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.