imarockstar Posted August 18, 2008 Share Posted August 18, 2008 Ok ... I am not sure if there is an easier way to grab the data fields from the database ... As of know I am typing them all out and with TABLES with over like 50 fields ..its a huge PAIN IN THE ASS !!! first I select the DB and what I want to see //from previous page $resumeid = $_GET['resumeid']; //select the table $result = mysql_query("select * from resume where resumeid='$resumeid'"); while($r=mysql_fetch_array($result)) { // how can I avoid doing this .. an array maybe ? $date =$r["date"]; $resumeid =$r["resumeid"]; $jobtitle =$r["jobtitle"]; $title =$r["title"]; $fname =$r["fname"]; $lname =$r["lname"]; $address =$r["address"]; $city =$r["city"]; $state =$r["state"]; $zipcode =$r["zipcode"]; $phone1 =$r["phone1"]; $phone2 =$r["phone2"]; $salary =$r["salary"]; $rate =$r["rate"]; $eligibility =$r["eligibility"]; $travel =$r["travel"]; $startdate =$r["startdate"]; $notice =$r["notice"]; $heard =$r["heard"]; $resume =$r["resume"]; $comments =$r["comments"]; ?> after i type all that, i need to put the DB data into my html ... <h2 class=><?=$title ?> <?=$fname ?> <?=$lname ?></h2> <?=$resume ?> <?php } ?> how can I avoid typing out all the fields ??? Link to comment https://forums.phpfreaks.com/topic/120215-is-there-an-easier-way-to-do-this/ Share on other sites More sharing options...
uniflare Posted August 18, 2008 Share Posted August 18, 2008 you could always use the array variables directly, eg use $r['blah'] instead of $blah. If u NEED the variables, then yes, fortunately there is a way to assign the variables in a few simple lines: <?php //from previous page $resumeid = $_GET['resumeid']; //select the table $result = mysql_query("select * from resume where resumeid='$resumeid'"); while($r=mysql_fetch_array($result)) { $Inverted = array_flip($r); // Switch the array "ID"'s with the Array "Values" and assign the result to $Inverted $c = count($r); // Count how many variables need to be assigned For($i=0;$i<$c;$i++){ // Loop Each variable and assign $$Inverted[$i] = $r[$Inverted[$i]]; // This uses $$variablename, you assign a variable with the name of the value of $variablename. } } ?> This is infact harsh code, slow. Sticking with the original arrays is much faster and cleaner. This is how i personally would have this code: <?php //from previous page $resumeid = $_GET['resumeid']; //select the table $result = mysql_query("select * from resume where resumeid='$resumeid'"); while($r=mysql_fetch_array($result)) { $Results[] = $r; } ?> $Results would become a Multi-Dimensional array. Eg: $Results[1] = the first row. $Results[2]['state'] = The State from the Second Returned Row. --- Hope this helps, and happy coding Link to comment https://forums.phpfreaks.com/topic/120215-is-there-an-easier-way-to-do-this/#findComment-619374 Share on other sites More sharing options...
imarockstar Posted August 18, 2008 Author Share Posted August 18, 2008 thanks man .. I will try this out !!!! b Link to comment https://forums.phpfreaks.com/topic/120215-is-there-an-easier-way-to-do-this/#findComment-619398 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.