Click here to Skip to main content
15,900,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am fetching data from a column of another table and inserting so it adds the number columns in this table according to the number of data present in the first column, but its not working.


What I have tried:

$que='select n_quid from nsnsbl0122_qp order by n_quid asc';
$que1=mysql_query($que);
$que2=mysql_num_rows($que1);
$table  = 'ns22_sp';
 
for($i=0;$i<$que2;$i++){

   $ que3=mysql_fetch_array($que1);


    $add = mysql_query("ALTER TABLE $table
    ADD COLUMN ".$que3['n_quid']." SMALLINT(6) NOT NULL,
    AFTER f_ex_status");



};  


};
Posted
Comments
Richard MacCutchan 21-Jun-20 3:52am    
You are trying to add a new column for each row returned from the select query. Is that what you mean to do? Also, what does "not working" mean?
Member 11755075 21-Jun-20 4:04am    
yes am trying to add new column for each row returned and code works for just 1 value but doesnt work for multiple values
Richard MacCutchan 21-Jun-20 4:24am    
Well we cannot guess what is happening. You need to provide some specific details of the exact results when you run the code. It would probably help if you actually checked the result of your mysql calls rather than just assuming that they all succeed.
Member 11755075 21-Jun-20 4:49am    
i checked and it works for alphabets , like xc, cv, dc , but its not working for numbers as column names
Member 11755075 21-Jun-20 5:08am    
solved the problem , the problem was it was numbers which was being sent and i had to add ` (back ticks ) on both sides

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900