2

Add the custom result table to mysql_fetch_assoc

 3 years ago
source link: https://www.codesd.com/item/add-the-custom-result-table-to-mysql-fetch-assoc.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Add the custom result table to mysql_fetch_assoc

advertisements

is it possible to add custom data to the results so it can be used the same as the $results being returned?

ie i'd like to add a random number to the results;

$recordSet = mysql_query($sql,$this->conn);
$results = array();
while ($row = mysql_fetch_assoc($recordSet)){
    $results[]=$row;
    /// add to results[] a custom field and value, ie 'random' = 1000
}
return $results;

and then i can use it the same as;

foreach($results as $res) $title = $res['title'], $random = $res['random'];


Why not?

while ($row = mysql_fetch_assoc($recordSet)){
    $row['random'] = rand() * 1000;
    $results[] = $row;
}

Related Articles

foreach loop continues to add the previous result to the next one in each table row

I am trying to create a table that shows the date of a training plan, the plan its self and the members of the group that can attend. The first two are no problem but its who can attend that is the issue. The attendees is stored as a string in the da

Updating the custom wordpress table

I am building a dashboard with custom User Data. Each element on the dashboard goes into the loop and shows the related information regarding that user.I am able to show the the custom field using session and loops but i need to update the informatio

Rails migration t.belongs_to: user, add the custom column name seller_id?

I am trying to add seller_id to my items model in a migration by doing the following: rails g model Item title:string description:text price:bigint status:integer published_date:datetime seller:belongs_to This didn't work of course... ultimately I wa

Add the custom http header to all jQuery AJAX queries

Point of clarification: I don't have any problem adding a custom header to my jQuery ajax call, I want to have my custom header added to all ajax calls automatically. If you take a look at jquery $.ajax custom http headers issue (not my question), yo

How to add the custom tag, then add the value of an input field to the second input field using onkeyup?

Working scenario: The user have 2 input text field in which he can search a game tag and then append the searched tag value to the 2nd input field. Problem statement: The user want to add new custom tag that is not present in the searched list and th

How to get the name of the mysql result table?

The MySQL query is as follows SELECT t1.*, t2.*, t3.*, t4.*, t5.*, t6.* FROM table1 t1 INNER JOIN table2 t2 INNER JOIN table3 t3 INNER JOIN table4 t4 INNER JOIN table5 t5 INNER JOIN table6 t6 order by t1.updated_time, t2.updated_time, t3.updated_time

How do I return the custom result sets from the repository?

I have business models named Product and Orders like below: public class Product { public int ProductId {get; set;} public string Name {get; set;} } public class Order { public int OrderId{get; set;} public int ProductId {get; set;} ... } In my repos

Programmatically add the custom image view in MainActivity

I want to dynamically add my custom ImageView to the MainActivity which already contains a EditText such that the whole space under EditText should be covered by ImageView. Then I would draw something on ImageView upon TouchEvent and accordingly outp

How do I add the JSON results to a div each time I click the load more button?

On load of a page my getJSON call displays its output to a div (called myDiv). Now I want to add a button at the end of the page and when the user clicks that button, I want to make another call to getJSON, but this time I want to increment the page_

Dynamically add the custom HTML form file entry with jQuery

I have some jQuery, JavaScript, and CSS that allows me to customize the appearance of HTML form file inputs. I also have a bit of jQuery that allows users to dynamically add as many files as they need to attach. The problem I'm having is that after a

how to use UI NIB instead of loadNibNamed for the custom UI table cell in ios?

I am making a custom ui table view cell. I know i can use loadNibNamed method to use .xib of the cell but that causes scrolling to be slow when my I have too much data in it . I want to use UI nib because its lot faster than loadNibNamed method for l

WordPress theme options insert into the custom database table with $ wpdb-insert

I've been working out with this quite a long time and I can't find a way how to make it work. I'm creating a simple theme option with my theme but putting all the options to a custom database table. I want to know how $wpdb->insert() inserts all opti

Java 8 optional adds the return result only if option.isPresent

I have a piece of code where an interface has an Optional return method and some of the classes that implement it to return something, other don't. In an effort to embrace this brilliant "null killer", here is what I have tried: public interface

Objective C: I try to save an NSDictionary containing primitives and an object, but an error occurred after I tried to add the custom object

So I have this custom object i made called 'Box', it's throwing the error for that one. Inside of my NSDictionary is... box = [[Box alloc] initWithHeight:20 height:40]; wrap.dict = [NSMutableDictionary dictionaryWithObjectsAndKeys:numberInt, kInt, nu

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK