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 3275556
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T19:09:27+00:00 2026-05-17T19:09:27+00:00

Here is the code I have came up for this problem. $link = mysql_connect($host,

  • 0

Here is the code I have came up for this problem.

$link = mysql_connect($host, $user, $pass) or die("Can not connect to the host." . mysql_error());
mysql_select_db($db) or die("Can not connect to the particular database.");

$result = mysql_query("SHOW COLUMNS FROM ".$table."");
$i = 0;
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
$csv_output .= $row['Field']."; ";
$i++;
}
}
$csv_output .= "\n";

$values = mysql_query("SELECT * FROM ".$table." WHERE forwarded_oce='1'");
while ($rowr = mysql_fetch_row($values)) {
for ($j=0;$j<$i;$j++) {
$csv_output .= $rowr[$j]."; ";
$smallerid = $rowr[$i-1];
$smaller = mysql_query("SELECT budget FROM `db`.`table` WHERE id='$smallerid'");
}
$csv_output .= $smaller;
$csv_output .= "\n";
}

$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$filename.".csv");
print $csv_output;
exit;
?>

So, the issue is that when I try to add the extra column with additional information from a different mysql table it prints out blank. I cannot seem to find my mistake in the code, but maybe somebody knows, or have expierence with these tasks to at least point me in the right direction.

What I am trying to do is – combine data from 2 different MySQL tables, and identifier for the data selected from the second table comes from the last column of the first table.

If you know any framework with could help me solve this issues it would be perfect. I am banging my head against the wall with this problem for 2 days allready and official PHP documentation do not have problems like this in mysql_query section.
…..
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-05-17T19:09:27+00:00Added an answer on May 17, 2026 at 7:09 pm

    I am not sure what you are trying to do , but it seems like you want to take the last columns value and use it for finding a value from another table and add that to the record. For that i think something like this should work:

    $link = mysql_connect($host, $user, $pass) or die("Can not connect to the host." . mysql_error());
    mysql_select_db($db) or die("Can not connect to the particular database.");
    
    $csv_output = "";
    $last_col = "";
    $values = mysql_query("SELECT * FROM ".$table." WHERE forwarded_oce='1'");
    while ($rowr = mysql_fetch_assoc($values)) {
        if(!$csv_output){
            foreach($rowr as $fld_name => $fld_val){
                $csv_output .= $fld_name.", ";
                $last_col = $fld_name;
            }
            $csv_output .= "New_Field\n";
        }
    
        $smallerid = $rowr[$last_col];
        list($smaller) = mysql_fetch_row(mysql_query("SELECT budget FROM `db`.`table` WHERE id = '$smallerid'"));
        $rowr[] = $smaller;
    
        $csv_output .= implode(', ' , $rowr) ; 
        $csv_output .= "\n";
    }
    
    $filename = $file."_".date("Y-m-d_H-i",time());
    header("Content-type: application/vnd.ms-excel");
    header("Content-disposition: csv" . date("Y-m-d") . ".csv");
    header( "Content-disposition: filename=".$filename.".csv");
    print $csv_output;
    exit;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have this code here: <table> <tr> <td width=200px valign=top> <div class=left_menu> <div
I have this code here printf '$request1 = select * from whatever where this
I'm trying to brush up my algorithmic skills and came across this problem. Here
It's not the first time I'm bumping into this problem and never have the
I have this very long exercise and I came a cross a problem in
Hey guys, It's 5 am here, I was doing some code... when this came
I have came across this problem when using pointer to pointer to a char:
Here is the code I have written for Rectangle class. class Rectangle (l: Double,
enter code here I have a table on SQL server 2005 with bigint primary
Here is the code I have to create an UIAlertView with a textbox. UIAlertView

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.