Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8508773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:15:12+00:00 2026-06-11T03:15:12+00:00

I am a novice at PHP and i have encountered a problem with the

  • 0

I am a novice at PHP and i have encountered a problem with the following code…

<?php 
 // Connects to Database 
 mysql_connect("localhost", "root") or die(mysql_error()); 
 mysql_select_db("test") or die(mysql_error()); 
 $data = mysql_query("SELECT country_id, country_name FROM country, channels WHERE channels.channel_id = country.channel_id AND channels.channel_id = '1'") 
 or die(mysql_error()); 
  echo "<table border=0 cellpadding=15>";
echo "<tr align = center bgcolor=white>
<td><b>Country ID</b></td><td><b>Country Name</b></td>" ; 
 while (mysql_fetch_row($data)) {
$cid = mysql_result($data, 1);
$cname = mysql_result($data, 2);

# inserts value into table as a hyperlink

echo "<tr align = center bgcolor=white><td>$cid</td><td><a href=view_country_detail.php?cid=$cid>$cname</td>";
}

# displays table

print '</table>';

 ?>

to explain the problem i am getting, i am after generated hyperlinks to drill down to the companies which share the to be clicked country’s id from the code above to then display a similar layout on the ‘view_country_detail’ page. i cant work out why the output for the table gives me a repeated row for the first two id’s for the country column in the db. any help would be greatly appreciated as i am totally lost here. Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T03:15:14+00:00Added an answer on June 11, 2026 at 3:15 am

    Try structuring your while loop as follows:

    while($row = mysql_fetch_array($data)){
          $cid = $row[0];  //if you have the column names, replace 0 with 'column_name'
          $cname = $row[1];
    
          //then echo statement
     }
    

    Also, mysql_* functions have started the deprecation process and should no longer be used, even the php manual pages state the use of mysql_* is discouraged. Look into using the similar mysqli_* functions or PDO.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following php errors : A PHP Error was encountered Severity: Notice
Php novice. 1.Is there anything wrong with this PHP & MySQL code? include_once db_login.php
I'm a PHP novice, and I recently found this database-free pagination script on a
I am a novice in PHP. I have a URL and I need generate
I have this error in CI: A PHP Error was encountered Severity: Notice Message:
I am novice PHP programmer and I have created a function that changes an
We're currently running with php 5.2.5. We have now encountered a bug that creates
I am a complete novice at php and postgres. I have been searching all
I have this PHP code: <?php $float = 1,99; echo <p>$float<br>; $float = floatval($float);
I want insert following checkbox in a row from database table, but have error,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.