Pregunta

I've this problem with my PHP/SQL data retrieval from a remote database on my server.. The issue is that i created a database that has 2 columns (ID: Primary Key & Details: which holds Arabic Information that i want to be displayed on certain spaces on my website).

The problem is that i tried running a query to retrieve those data as follows: -

include ('config/setup.php');
##Database Retrieval Query: -
    ##High_Council_Query: -
        $id1='1';
        $high_council_query="SELECT * FROM home_content WHERE id=$id1";
        $data1 = mysql_query($high_council_query,$dbc) or die(mysql_error());
        mysql_query("SET NAMES utf8 COLLATE utf8_general_ci");
        $high_council_result= mysql_fetch_assoc($data1);

        $hcr = $high_council_result['details'];
        echo $hcr;

This is basically what i'm trying to do, i want to query the database to retrieve the value of details column where id = 1, and i want to take that value then view it on a certain spot where i've made CSS and HTML rules for using a $variable that has that single content..

Yet the problem is that it spits the result of the field too many times when i try to echo the $hcr which holds what i need it displays the same result over 6 times.. and ruins my page.. please help me with this error thanks ^_^

¿Fue útil?

Solución

To help you understand why this data is being output more than once I'll give you some general debugging advice.

The aim in this case is to find out where the repeated data is coming from.

I would start by creating a test variable $testing = 0 in the first line of the php file. Then replace

echo $hcr;

With:

$testing ++;
echo $hcr.' Loop:'.$testing;

This will determine if this section of code is being executed more than once. If it is it will also tell you how meany times.

If the string Loop:... is not displayed with the other instances of the data then you are useing echo $hcr in other places in your code.

Edit:

Because the counter is not being incremented the php file must be included more than once. Check for include xyz.php; in the main php file, probably index.php.

Otros consejos

just delete $high_council_result= mysql_fetch_assoc($data1); and simply use $data1 to view

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top