
vjmehra
Members-
Posts
22 -
Joined
-
Last visited
Profile Information
-
Gender
Not Telling
vjmehra's Achievements

Newbie (1/5)
0
Reputation
-
The <form></form> tags were indeed causing the issue! Thanks for that, I didn't realise you couldn't nest them. In-fact, I actually thought that is what I had to do (initially) in this instance, so I appreciate you're help and also I've learnt something, so all good :-)
-
Sorry just to ensure I understand what you are saying...when you say nested forms are invalid, you mean: <form> <form> Code </form> </form> Is invalid? But the following: <form> Code </form> <form> Code </form> Is okay? I tried removing the nesting, but the same result occurs. I still don't understand why if this shouldn't work at all, why it would work for rows 2 onwards. That aside, I will tidy up the code and re-post, but I can't remove the multiple <form> tags completely, as otherwise nothing will work!
-
I'm sure the clue is in the var_dump....but I can't work out how to interpret what it is saying!
-
By clicking the button in reduced_view_issues.php this then fires the script select_issue3.php, which runs an if statement and for this particular case, then fires select_issue.php. This all works correctly, otherwise it wouldn't work for rows 2 onwards surely? I have multiple <form> tags per page, this is because each row needs to be submitted on a button click, so there are multiple tags by design, however I hadn't noticed up until now that row 1 never worked!
-
Ooops! The variable is $issueid Sorry, I thought it would be better to post all the code, rather than leave gaps :-(
-
Using the following code: <html> <head> <title>Issues- Reduced View</title> </head> <body marginheight="0" topmargin="0" marginwidth="0" leftmargin="0" style="margin:0;padding:0" bgcolor="#B0E0E6"> <h1></h1> <form action="reduced_view_issues.php" method="post"> <?php //ini_set("display_errors","Off"); $server_name='xxx'; $user_name=''xxx'; $password='xxx'; $database_name='xxx'; $db1= new mysqli($server_name, $user_name, $password, $database_name); include_once('functions.php'); if(is_numeric($_POST['ddsub_sector_id'])) {$subsectorid=$_POST['ddsub_sector_id'];} else {$subsectorid='1';} if(empty($_POST['tbtickersearch'])) {$bondticker="'%'";} else {$bondticker="'".$_POST['tbtickersearch']."%'";} if(is_numeric($_POST['ddcurrency_id'])) {$currencyid=$_POST['ddcurrency_id'];} else {$currencyid='NULL';} if(is_numeric($_POST['ddcountry_id'])) {$countryid=$_POST['ddcountry_id'];} else {$countryid='NULL';} if(empty($_POST['tbenterticker'])) {$enterticker='NULL';} else {$enterticker="'".$_POST['tbenterticker']."'";} if(empty($_POST['tbenterlevel'])) {$enterlevel='NULL';} else {$enterlevel="'".$_POST['tbenterlevel']."'";} if(is_numeric($_POST['ddquote_convention_id'])) {$quoteconventionid=$_POST['ddquote_convention_id'];} else {$quoteconventionid='NULL';} if(is_numeric($_POST['ddbenchmark_id'])) {$benchmarkid=$_POST['ddbenchmark_id'];} else {$benchmarkid='NULL';} if(empty($_POST['tbentermaturity'])) {$entermaturity='NULL';} else {$entermaturity="'".$_POST['tbentermaturity']."'";} $result=get_dataset($db1,"call sp_filter_issues_reduced_view(".$subsectorid.",".$bondticker.",".$currencyid.",".$countryid.")"); //$result2=get_dataset($db1,"call sp_filter_issues_reduced_view(".$subsectorid.",".$bondticker.",".$currencyid.",".$countryid.")"); //$db1->close(); /*var_dump($stat_array);*/ ?> <table border="0"; style="border-collapse:collapse; border:solid 1px black"; bgcolor='#C0C0C0' width=100%> <tr bgcolor='#C0C0C0' width=100%> <td align='center'> <table style="border-collapse:collapse; border:solid 1px #C0C0C0"; bgcolor='#C0C0C0'> <tr bgcolor='#C0C0C0' width=100%> <td style="width: auto"> Select Sub Sector <?php simple_drop_down('ddsub_sector_id','sub_sector_id','sub_sector_name',$db1,"call sp_sub_sector",0,$subsectorid); ?> </td> <td > </td> <td style="width: auto"> Enter Description <?php echo "<input type='text' name='tbtickersearch' value='".$_POST['tbtickersearch']."'/>"; ?> </td> <td style="width: auto"> Select Currency <?php simple_drop_down('ddcurrency_id','currency_id','currency_ticker',$db1,"call sp_currency",1,$currencyid);?> </td> <td style="width: auto"> Select Country <?php simple_drop_down('ddcountry_id','country_id','country_code',$db1,"call sp_country",1,$countryid);?> </td> <td style="width: auto"> <input type='submit' name='btnsearch' value='Search' style="width: auto"> </td> </tr> </table> </td> <td align='center'> <table style="border-collapse:collapse; border:solid 1px #C0C0C0"; bgcolor='#C0C0C0'> <tr bgcolor='#C0C0C0' width=100%> <td style="width: auto"> Enter Description <?php echo "<input type='text' name='tbenterticker' value='".$_POST['tbenterticker']."'/>"; ?> </td> <td style="width: auto"> Enter Level <?php echo "<input type='text' name='tbenterlevel' value='".$_POST['tbenterlevel']."'/>"; ?> </td> <td style="width: auto"> Select Quote Convention <?php simple_drop_down('ddquote_convention_id','quote_convention_id','quote_convention_name',$db1,"call sp_all_quote_convention",1,$quoteconventionid);?> </td> <td style="width: auto"> Select Benchmark <?php simple_drop_down('ddbenchmark_id','issue_id','description',$db1,"call sp_benchmark",1,$benchmarkid);?> </td> <td style="width: auto"> Enter Call/Maturity <?php echo "<input type='text' name='tbentermaturity' value='".$_POST['tbentermaturity']."'/>"; ?> </td> <td style="width: auto"> <input type='submit' name='btncurve' value='View Curve' style="width: auto"> </td> </tr> </table> </td> </tr> <tr> <table border="1"; style="border-collapse:collapse; border:solid 1px black"; bgcolor='white'> <tr bgcolor='#C0C0C0'> <td align='center' style="border-collapse:collapse; border:solid 1px black; width: auto";>Description</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Currency</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Call Date</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Maurity Date</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>ISIN</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Moody</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Fitch</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>S&P</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Capital Type</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Bid ASW</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";></td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Ask ASW</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Bid Sprd</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";></td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Ask Sprd</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Bid Price</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";></td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Ask Price</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Bid YTC</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";></td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Ask YTC</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Bid YTM</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";></td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Ask YTM</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Date</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Time</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Source</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Change on Day</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Change from Issue</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Quote Convention</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Price To</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Current Benchmark</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Issue Swap Spread</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Issue Benchmark Spread</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Issue Price</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Coupon Step</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Amt Issued</td> <td align='center' style="border-collapse:collapse; border:solid 1px black";>Amt Outstanding</td> </tr> <?php $irow=0; foreach ($result as $row) { echo "<form action='select_issue3.php' method='post'>"; if ($irow % 2 != 0) # An odd row $colour = "6699FF"; else # An even row $colour = "white"; if (max($_POST['issueid'])==$row['issue_id']) $colour="yellow"; echo "<tr bgcolor=".$colour.">"; echo "<td style='white-space: nowrap; width: auto; border-collapse:collapse; border:solid 1px black';>"; echo "<input type='submit' style='width: auto' id='bonddescription' name='bonddescription[]' value='" .$row['description']."'><input type='hidden' id='issueid' name='issueid[]' value='".$row['issue_id']."'>"; echo "</td>"; ?> <td style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['currency_ticker'];?> </td> <td style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['first_call_date'];?> </td> <td style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['maturity_date'];?> </td> <td style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['isin'];?> </td> <td style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['moody'];?> </td> <td style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['fitch'];?> </td> <td style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['sandp'];?> </td> <td style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['capital_name'];?> </td> <td align='right' style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['bid_asw'];?> </td> <td align='center' style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> / </td> <td align='left' style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['ask_asw'];?> </td> <td align='right' style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['bid_sprd'];?> </td> <td align='center' style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> / </td> <td align='left' style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['ask_sprd'];?> </td> <td align='right' style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['bid_price'];?> </td> <td align='center' style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> / </td> <td align='left' style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['ask_price'];?> </td> <td align='right' style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['bid_ytc'];?> </td> <td align='center' style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> / </td> <td align='left' style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['ask_ytc'];?> <td align='right' style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['bid_ytm'];?> </td> <td align='center' style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> / <td align='left' style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['ask_ytm'];?> </td> <td style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['price_date'];?> </td> <td style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['price_time'];?> </td> <td style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['source_code'];?> </td> <td style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo number_format($row['cod'],3);?> </td> <td style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo number_format($row['change_from_issue'],3);?> </td> <td style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['quote_convention_name'];?> </td> <td style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['price_to_name'];?> </td> <td style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['current_benchmark_description'];?> </td> <td style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['issue_swap_spread'];?> </td> <td style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['issue_benchmark_spread'];?> </td> <td style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['issue_price'];?> </td> <td style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['coupon_step'];?> </td> <td style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['amount_issued']/1000000;?> </td> <td style='white-space: nowrap; border-collapse:collapse; border:solid 1px black';> <?php echo $row['amount_outstanding']/1000000;?> </td> </tr> <?php $irow++; echo "</form>"; } var_dump($_POST); ?> </table> </tr> </table> </form> </body> When I click on any button, i.e. the following fires: echo "<input type='submit' style='width: auto' id='bonddescription' name='bonddescription[]' value='" .$row['description']."'><input type='hidden' id='issueid' name='issueid[]' value='".$row['issue_id']."'>"; This works correctly....except for the first row of any dataset. If there is 1 row it doesn't work, if there are 6 rows, row 1 still doesn't work, yet the rest do! select_issue3.php contains the following: if (isset($_POST['bonddescription'])) {include_once('reduced_view_issues.php'); include_once('select_issue.php'); } which must be firing correctly, as the page works for any row other than 1. This is select_issue.php: <html> <head> <title>Sectors</title> </head> <body marginheight="0" topmargin="0" marginwidth="0" leftmargin="0" style="margin:0;padding:0" bgcolor="#B0E0E6"> <form action="select_issue3.php" method="post"> <?php //if(empty(max($_POST['issueid'])) {$issueid='NULL';} else {$issueid="'".max($_POST['issueid'])."'";} $bond_issue_id=max($_POST['issueid']); include_once('functions.php'); $server_name='xxx'; $user_name=''xxx'; $password='xxx'; $database_name='xxx'; $result_array=get_dataset($db1,"call sp_select_issue(".$bond_issue_id.")"); foreach ($result_array as $row) { $bond_description = $row['description']; $bond_issue_id = $row['issue_id']; ?> <table border="1" style="border:solid black" cellpadding="0" cellspacing="0" width="100%" bgcolor='white'> <td><table width='100%'> <tr> <td align='center'> <form action="select_issue3.php" method="post"> <input type='submit' name='btnedit' value='Edit <?php echo $bond_description;?>'> <?php echo "<input type='hidden' id='issueid' name='issueid[]' value='".$bond_issue_id."'>"; ?> </form> </td> </tr> <tr> <td align="left">Notes</td> <td> <?php echo $row['notes'];?> </td> </tr> <tr> <td align="left">Benchmark</td> <td> <?php if($row['benchmark_bond_cb']="1") {$checked='checked';} ?> <?php echo "<input type='Checkbox' id='value' disabled='true' value='".$checked."' checked=".$checked." name='cbbenchmarkid[]' >"; ?> </td> </tr> </table> </td> <td> <table width='100%'> <tr> <td align="left">Currency</td> <td> <?php echo $row['currency_ticker'];?> </td> </tr> <tr> <td align="left">Coupon</td> <td> <?php echo $row['coupon'];?> </td> </tr> <tr> <td align="left">Coupon Type</td> <td> <?php echo $row['coupon_type_name'];?> </td> </tr> <tr> <td align="left">Coupon Frequency</td> <td> <?php echo $row['coupon_frequency_code'];?> </td> </tr> <tr> <td align="left">Day Count</td> <td> <?php echo $row['day_count_name']; ?> </td> </tr> </table> </td> <td> <table width='100%'> <tr> <td> Bookrunners </td> <td> Exchanges </td> </tr> <tr> <td> <table> <?php $result_array2=get_dataset($db1,"call sp_bookrunner(".$bond_issue_id.")"); foreach ($result_array2 as $row2) { echo "<tr>".$row2['bond_ticker']."</tr>"; } ?> </table> </td> <td> <table valign='top'> <?php $result_array3=get_dataset($db1,"call sp_exchange_issue(".$bond_issue_id.")"); foreach ($result_array3 as $row3) { echo "<tr><td valign='top'>".$row3['exchange_code']."</td></tr>"; } ?> </table> </td> </tr> </table> </td> <td> <table width='100%'> <tr> <td align="left">Price To</td> <td> <?php echo $row['price_to_name'];?> </td> </tr> <tr> <td align="left">Quote Convention</td> <td> <?php echo $row['quote_convention_name'];?> </td> </tr> </table> </td> </tr> <tr> <td> <table width='100%'> <tr> <td align="left">Issuer</td> <td> <?php echo $row['issuer_name'];?> </td> </tr> <tr> <td align="left">Guarantor</td> <td> <?php echo $row['guarantor_name'];?> </td> </tr> <tr> <td align="left">Sub Sector</td> <td> <?php echo $row['sub_sector_name'];?> </td> </tr> <tr> <td align="left">Market</td> <td> <?php echo $row['market_name'];?> </td> </tr> </table> </td> <td> <table width='100%'> <tr> <td align="left">CUSIP</td> <td> <?php echo $row['cusip'];?> </td> </tr> <tr> <td align="left">Bloomberg Number</td> <td> <?php echo $row['bloomberg_number'];?> </td> </tr> <tr> <td align="left">ISIN</td> <td> <?php echo $row['isin'];?> </td> </tr> </table> </td> <td> <table width='100%'> <tr> <td align="left">Moody</td> <td> <?php echo $row['moody'];?> </td> </tr> <tr> <td align="left">Fitch</td> <td> <?php echo $row['fitch'];?> </td> </tr> <tr> <td align="left">S&P</td> <td> <?php echo $row['sandp'];?> </td> </tr> </table> </td> <td> <table width='100%'> <td align="left">Capital Type</td> <td> <?php echo $row['capital_name'];?> </td> </tr> <tr> <td align="left">Collateral Type</td> <td> <?php echo $row['collateral_type_name'];?> </td> </tr> </table> </td> </tr> <tr> <td> <table width='100%'> <tr> <td align='right'>Bid ASW</td> <td align='center'></td> <td align='left'>Ask ASW</td> <td align='right'>Bid Sprd</td> <td align='center'></td> <td align='left'>Ask Sprd</td> <td align='right'>Bid Price</td> <td align='center'></td> <td align='left'>Ask Price</td> <td align='right'>Bid YTC</td> <td align='center'></td> <td align='left'>Ask YTC</td> <td align='right'>Bid YTM</td> <td align='center'></td> <td align='left'>Ask YTM</td> <td>Date</td> <td>Time</td> <td>Source</td> </tr> <tr> <?php $result_array4=get_dataset($db1,"call sp_last_price(".$bond_issue_id.",5)"); foreach ($result_array4 as $row4) { ?> <td align='right'> <?php echo $row4['bid_asw'];?> </td> <td align='center'> / </td> <td align='left'> <?php echo $row4['ask_asw'];?> </td> <td align='right'> <?php echo $row4['bid_sprd'];?> </td> <td align='center'> / </td> <td align='left'> <?php echo $row4['ask_sprd'];?> </td> <td align='right'> <?php echo $row4['bid_price'];?> </td> <td align='center'> / </td> <td align='left'> <?php echo $row4['ask_price'];?> </td> <td align='right'> <?php echo $row4['bid_ytc'];?> </td> <td align='center'> / </td> <td align='left'> <?php echo $row4['ask_ytc'];?> </td> <td align='right'> <?php echo $row4['bid_ytm'];?> </td> <td align='center'> / </td> <td align='left'> <?php echo $row4['ask_ytm'];?> </td> <td> <?php echo $row4['price_date'];?> </td> <td> <?php echo $row4['price_time'];?> </td> <td> <?php echo $row4['exchange_code'];?> </td> </tr> <?php } ?> </table> </td> <td> <table width='100%'> <tr> <td align="left">Issue Benchmark</td> <td> <?php echo $row['issue_benchmark_description'];?> </td> </tr> <tr> <td align="left">Current Benchmark</td> <td> <?php echo $row['current_benchmark_description'];?> </td> </tr> <tr> <td align="left">Issue Swap Spread</td> <td> <?php echo $row['issue_swap_spread'];?> </td> </tr> <tr> <td align="left">Issue Benchmark Spread</td> <td> <?php echo $row['issue_benchmark_spread'];?> </td> </tr> <tr> <td align="left">Issue Price</td> <td> <?php echo $row['issue_price'];?> </td> </tr> <tr> <td align="left">Coupon Step</td> <td> <?php echo $row['coupon_step'];?> </td> </tr> </table> </td> <td> <table width='100%'> <tr> <td align="left">Announcement Date</td> <td> <?php echo $row['announcement_date'];?> </td> </tr> <tr> <td align="left">Interest Accrual Date</td> <td> <?php echo $row['interest_accrual_date'];?> </td> </tr> <tr> <td align="left">First Settlement Date</td> <td> <?php echo $row['first_settle_date'];?> </td> </tr> <tr> <td align="left">First Coupon Date</td> <td> <?php echo $row['first_coupon_date'];?> </td> </tr> <tr> <td align="left">Maurity Date</td> <td> <?php echo $row['maturity_date'];?> </td> </tr> <tr> <td align="left">Call Date</td> <td> <?php echo $row['first_call_date'];?> </td> </tr> </table> </td> <td> <table width='100%'> <tr> <td align="left">Amount Issued</td> <td> <?php echo number_format($row['amount_issued']);?> </td> <td></td> </tr> <tr> <td align="left">Amount Outstanding</td> <td> <?php echo number_format($row['amount_outstanding']);?> </td> </tr> <tr> <td align="left">Minimum Size</td> <td> <?php echo number_format($row['min_size']);?> </td> </tr> <tr> <td align="left">Increment</td> <td> <?php echo number_format($row['increment']);?> </td> </tr> <tr> <td align="left">Par Amount</td> <td> <?php echo number_format($row['par_amount']);?> </td> </tr> </table> </td> </tr> </table> <?php } //$db1->close(); ?> </form> </body> </html> functions.php is as follows (I don't believe there are any issues here): <?php //---------------------------------------------------------------------- $server_name='xxx'; $user_name=''xxx'; $password='xxx'; $database_name=''xxx'; $db1= new mysqli($server_name, $user_name, $password, $database_name); //---------------------------------------------------------------------- /*function db_result_to_array($db1, $query_string){ //--------------------------------------------------------------------- $result = $db1->query($query_string); $res_array = array(); while($res_away = $result->fetch_assoc()){ $field_id="'".$field_id."'"; $results[ $result[$field_id]] =$result; } //--------------------------------------------------------------------- */ function get_combobox_dataset($db1, $query_string) { //--------------------------------------------------------------------- $result2 = $db1->query($query_string); if($result2 === false) { echo 'Error!'; } else { // do the fetching... } /* $num_results = $result1->num_rows; $res_array = array(); for ($count=0; $row = $result1->fetch_assoc(); $count++) { $res_array[$count]=$row; } return $res_array;*/ } //--------------------------------------------------------------------- function get_dataset($db1, $query_string) { //--------------------------------------------------------------------- $result1 = $db1->query($query_string); //$num_results = $result1->num_rows; if (! $result1) die($db1->error); $num_results = $result1->num_rows; $res_array = array(); while ($row = $result1->fetch_assoc()) { $res_array[]=$row; } //$query_string->free(); $result1->free(); //#MAD Add these lines to "clear the pipe" after a Stored Procedure Call while ($db1->more_results()) { $db1->next_result(); // #MAD I'm not sure if these two lines are needed or not // $result = $db1->store_result(); //$result1->free(); } return $res_array; } //--------------------------------------------------------------------- function get_sub_dataset($db1, $query7,$sub_field_id) { //--------------------------------------------------------------------- $query1 = $query7; $result1 = $db1->query($query1); $num_results = $result1->num_rows; //$result8 = db_result_to_array($result1); return $result1;} $query1->free; $result1->free; //--------------------------------------------------------------------- function drop_down($array_name,$field_id, $query_field_id, $field_name,$db1,$query_string,$row,$multiple=0,$query_string2=0,$sub_field_id=0) { //------------------------------------------------------------------------------------------------------------------------- $stat_array=get_dataset($db1,$query_string); //echo "<select name=".$array_name." width='100%'>"; if(empty($multiple)) { echo "<select name=".$array_name." width='100%'>"; if ($row[$field_id] == $thiscat[$query_field_id]) {}{echo "<option>None Selected</option>";} foreach ($stat_array as $thiscat) { echo '<option value="' . $thiscat[$query_field_id] . '"'; if ($row[$field_id] == $thiscat[$query_field_id]) {echo ' selected';} echo '>' . $thiscat[$field_name] . '</option>'; } } else {echo "<select multiple size =".$multiple." name=".$array_name." width='100%'>"; foreach ($stat_array as $thiscat) { echo '<option value="' . $thiscat[$query_field_id] . '"'; $list_box_array=get_dataset($db1,$query_string2); foreach ($list_box_array as $list_box_row) { if ($list_box_row[$sub_field_id] == $thiscat[$query_field_id]) {echo ' selected';} } echo '>' . $thiscat[$field_name] . '</option>'; } } echo "</select>"; } //------------------------------------------------------------------------------------------------------------------------- function simple_drop_down($drop_down_name,$field_id,$field_name,$db1, $query_string, $none=0, $default_value=0) { //----------------------------------------------------------------------------------------------------------------------------------- /*$stat_array=get_dataset($db1,"select * from tblcurrency;"); var_dump($stat_array);*/ echo "<select name=".$drop_down_name.">"; $stat_array=get_dataset($db1,$query_string); if ($none == 1) {echo "<option>None Selected</option>";} foreach ($stat_array as $thisstat){ echo "<option value=\"".$thisstat[$field_id]."\""; if ($default_value == $thisstat[$field_id]) {echo ' selected';} echo ">".$thisstat[$field_name]."</option>"; } echo "</select>"; } //----------------------------------------------------------------------------------------------------------------------------------- ?> As usual, I'm completely clueless and can't figure this one out, how can rows 2 onwards work, yet not row 1!!!! If it makes a difference the var_dump for row 1 for some reason includes controls above it on the page, for example: var_dump for row 1: array(11) { ["ddsub_sector_id"]=> string(1) "1" ["tbtickersearch"]=> string(0) "" ["ddcurrency_id"]=> string(13) "None Selected" ["ddcountry_id"]=> string(13) "None Selected" ["tbenterticker"]=> string(0) "" ["tbenterlevel"]=> string(0) "" ["ddquote_convention_id"]=> string(13) "None Selected" ["ddbenchmark_id"]=> string(13) "None Selected" ["tbentermaturity"]=> string(0) "" ["bonddescription"]=> array(1) { [0]=> string(17) "BACR 5.000 4/2013" } ["issueid"]=> array(1) { [0]=> string(2) "97" } } var_dump for row 2: array(2) { ["bonddescription"]=> array(1) { [0]=> string(18) "BACR 6.000 12/2017" } ["issueid"]=> array(1) { [0]=> string(2) "99" } } I'm hoping someone can figure it out from this, as I don't understand why the var_dump includes all the extra info (as well as the correct info), yet somehow the correct info isn't collected when I try to capture it using $_POST....
-
Ok this does appear to be working! Thanks for your help, I'm sort of going through the code, trying to understand why this works, not entirely sure I do to be honest, but I'm glad it does :-)
-
I did what you said (hopefully correctly), so this is the code: function get_dataset($db1, $query_string) { //--------------------------------------------------------------------- $result1 = $db1->query($query_string); //$num_results = $result1->num_rows; if (! $result1) die($db1->error); $num_results = $result1->num_rows; $res_array = array(); while ($row = $result1->fetch_assoc()) { $res_array[]=$row; } //$query_string->free(); $result1->free(); return $res_array; } //--------------------------------------------------------------------- The error was exactly what you predicted: Commands out of sync; you can't run this command now ....so what steps should I take next? I'm not sure I understand the problem here, are you saying this message suggests the issue is with the database, not the php?
-
DavidAM- The query displays correctly if I have one dataset, I simply use the same query for the second dataset and I get the error, so the SQL and result are both fine.
-
I re-wrote the function as (I think) you are suggesting: function get_dataset($db1, $query_string) { //--------------------------------------------------------------------- $result1 = $db1->query($query_string); //$num_results = $result1->num_rows; $num_results = $result1->num_rows; $res_array = array(); while ($row = $result1->fetch_assoc()) { $res_array[]=$row; } $query_string->free(); $result1->free(); return $res_array; } //--------------------------------------------------------------------- However now I just get the error: Fatal error: Call to a member function free() on a non-object in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\Blue_Ocean\functions.php on line 68 If I comment out the ....->free() bits....I just get the fetch_assoc() error again.
-
It makes no difference whether I include the return function or not unfortunately...it always keeps coming back to: for ($count=0; $row = $result1->fetch_assoc(); $count++) { $res_array[$count]=$row; } It doesn't like the second dataset somehow, just keeps coming back with 'Fatal error: Call to a member function fetch_assoc()', however if I just have 1 dataset its fine! I'm sure this must be really obvious to someone who knows what they're talking about, but I'm really stuck :-(
-
I have a function: //---------------------------------------------------------------------- $server_name='xxx'; $user_name='xxx'; $password='xxx'; $database_name='xxx'; $db1= new mysqli($server_name, $user_name, $password, $database_name); //---------------------------------------------------------------------- function get_dataset($db1, $query_string) { //--------------------------------------------------------------------- $result1 = $db1->query($query_string); //$num_results = $result1->num_rows; $num_results = $result1->num_rows; $res_array = array(); for ($count=0; $row = $result1->fetch_assoc(); $count++) { $res_array[$count]=$row; } return $res_array; //$result8 = db_result_to_array($result1); //return $result1; $query_string->free(); $result1->free(); //$db1->close(); } //--------------------------------------------------------------------- Now, this works fine, sort of.... On a separate page, I call the function: $result=get_dataset($db1,"call sp_filter_issues_reduced_view(".$subsectorid.",".$bondticker.",".$currencyid.",".$countryid.")"); This works fine, however, I also have a few comboboxes I want to pull datasets into. This wasn't working, so just to test, I tried the following: $result=get_dataset($db1,"call sp_filter_issues_reduced_view(".$subsectorid.",".$bondticker.",".$currencyid.",".$countryid.")"); $result2=get_dataset($db1,"call sp_filter_issues_reduced_view(".$subsectorid.",".$bondticker.",".$currencyid.",".$countryid.")"); So the 2nd, is simply a copy/paste of the first, yet it returns this error: Fatal error: Call to a member function fetch_assoc() on a non-object in FILE PATH\functions.php on line 33 (line 33 being the line including fetch_assoc() in the function get_dataset, shown above). Now, from this, I'm assuming somehow my dataset isn't clearing properly, or something like that. If I call the function once it works, twice it doesn't. This is really bugging me and has been for weeks now, so I'd really appreciate it, if anyone could help out!!!
-
sadly that doesn't seem to work, produces similar results to my effort :-(
-
I thought I'd knock up a quick simple form to show what I mean, not sure if this helps or not: <html> <head> <title></title> </head> <body marginheight="0" topmargin="0" marginwidth="0" leftmargin="0" style="margin:0;padding:0" bgcolor="#B0E0E6"> <h1></h1> <form action="" method="post"> <?php @ $db = new mysqli('xxx', 'xxx', 'xxx', 'xxx'); $query = "call sp_view_all_venues();"; $result = $db->query($query); $num_results = $result->num_rows; function db_result_to_array($result){ //--------------------------------------------------------------------- $res_array = array(); for ($count=0; $row = $result->fetch_assoc(); $count++) { $res_array[$count]=$row; } return $res_array; } //--------------------------------------------------------------------- echo "<input type='submit' id='btnupdate' name='btnupdate' value='Update & Delete' >"; $irow=0; while($row = $result->fetch_assoc()) { if($row['venue1']==1) $checked=" checked='checked'"; else $checked=''; if($row['venue2']==1) $checked2=" checked='checked'"; else $checked2=''; echo "<table><tr><td>"; echo "<input type='radio' name='".$row[venue_id']."[]' value='1'".$checked."/>".$row['venue_id']; echo "<input type='radio' name='".$row['venue_id']."[]' value='0'".$checked2." />P2"; echo "</td>"; $irow++; } echo "</tr></table>"; var_dump($_POST); ?> </form> </body> </html> the var dump shows: array(85) { ["btnupdate"]=> string(15) "Update & Delete" [92]=> array(1) { [0]=> string(1) "1" } [90]=> array(1) { [0]=> string(1) "0" } [91]=> array(1) { [0]=> string(1) "0" } [88]=> array(1) { [0]=> string(1) "0" } [89]=> array(1) { [0]=> string(1) "0" } [87]=> array(1) { [0]=> string(1) "0" } [80]=> array(1) { [0]=> string(1) "0" } [79]=> array(1) { [0]=> string(1) "0" } [78]=> array(1) { [0]=> string(1) "0" } [77]=> array(1) { [0]=> string(1) "0" } [76]=> array(1) { [0]=> string(1) "0" } [75]=> array(1) { [0]=> string(1) "0" } [74]=> array(1) { [0]=> string(1) "0" } [73]=> array(1) { [0]=> string(1) "0" } [72]=> array(1) { [0]=> string(1) "0" } [71]=> array(1) { [0]=> string(1) "0" } [70]=> array(1) { [0]=> string(1) "0" } [69]=> array(1) { [0]=> string(1) "0" } [68]=> array(1) { [0]=> string(1) "0" } [67]=> array(1) { [0]=> string(1) "0" } [66]=> array(1) { [0]=> string(1) "0" } [65]=> array(1) { [0]=> string(1) "0" } [64]=> array(1) { [0]=> string(1) "0" } [63]=> array(1) { [0]=> string(1) "0" } [62]=> array(1) { [0]=> string(1) "0" } [61]=> array(1) { [0]=> string(1) "0" } [16]=> array(1) { [0]=> string(1) "0" } [15]=> array(1) { [0]=> string(1) "0" } [14]=> array(1) { [0]=> string(1) "0" } [13]=> array(1) { [0]=> string(1) "0" } [12]=> array(1) { [0]=> string(1) "0" } [11]=> array(1) { [0]=> string(1) "0" } [60]=> array(1) { [0]=> string(1) "0" } [59]=> array(1) { [0]=> string(1) "0" } [10]=> array(1) { [0]=> string(1) "0" } [9]=> array(1) { [0]=> string(1) "0" } [8]=> array(1) { [0]=> string(1) "0" } [7]=> array(1) { [0]=> string(1) "0" } [6]=> array(1) { [0]=> string(1) "0" } [5]=> array(1) { [0]=> string(1) "0" } [56]=> array(1) { [0]=> string(1) "0" } [55]=> array(1) { [0]=> string(1) "0" } [54]=> array(1) { [0]=> string(1) "0" } [53]=> array(1) { [0]=> string(1) "0" } [52]=> array(1) { [0]=> string(1) "0" } [51]=> array(1) { [0]=> string(1) "0" } [50]=> array(1) { [0]=> string(1) "0" } [4]=> array(1) { [0]=> string(1) "0" } [3]=> array(1) { [0]=> string(1) "0" } [58]=> array(1) { [0]=> string(1) "0" } [57]=> array(1) { [0]=> string(1) "0" } [49]=> array(1) { [0]=> string(1) "0" } [48]=> array(1) { [0]=> string(1) "0" } [47]=> array(1) { [0]=> string(1) "0" } [46]=> array(1) { [0]=> string(1) "0" } [45]=> array(1) { [0]=> string(1) "0" } [44]=> array(1) { [0]=> string(1) "0" } [43]=> array(1) { [0]=> string(1) "0" } [42]=> array(1) { [0]=> string(1) "0" } [41]=> array(1) { [0]=> string(1) "0" } [40]=> array(1) { [0]=> string(1) "0" } [39]=> array(1) { [0]=> string(1) "0" } [38]=> array(1) { [0]=> string(1) "0" } [37]=> array(1) { [0]=> string(1) "0" } [36]=> array(1) { [0]=> string(1) "0" } [35]=> array(1) { [0]=> string(1) "0" } [34]=> array(1) { [0]=> string(1) "0" } [33]=> array(1) { [0]=> string(1) "0" } [32]=> array(1) { [0]=> string(1) "0" } [31]=> array(1) { [0]=> string(1) "0" } [30]=> array(1) { [0]=> string(1) "0" } [29]=> array(1) { [0]=> string(1) "0" } [21]=> array(1) { [0]=> string(1) "0" } [20]=> array(1) { [0]=> string(1) "0" } [19]=> array(1) { [0]=> string(1) "0" } [18]=> array(1) { [0]=> string(1) "0" } [17]=> array(1) { [0]=> string(1) "0" } [28]=> array(1) { [0]=> string(1) "0" } [27]=> array(1) { [0]=> string(1) "0" } [26]=> array(1) { [0]=> string(1) "0" } [25]=> array(1) { [0]=> string(1) "0" } [24]=> array(1) { [0]=> string(1) "0" } [23]=> array(1) { [0]=> string(1) "0" } [22]=> array(1) { [0]=> string(1) "0" } } Which is expected, but I have no idea how to extract and make sense of the submitted data....
-
Hi, I have 2 radio button's within a table and need to pass this array. All other rows within my table can be sent as array's and captured using $_POST['field_name'][$ROW 1 value etc]. However for radio buttons this doesn't work. As an example, a standard textbox I can send an array using the following: echo "<td width='33%'><input type='Textbox' width='100%' id='test' name='test[]' value='" .$row['test']. "'></td>"; I can then capture it using: $test = $_POST['test'][$iLine]; This works, no problem, however for radio buttons, I can't use a static array name, as presumably it dumps all rows into the array, if I do this, only the last row has a checked button, hence I need to use the following (where $checked includes the logic to decide whether the button should be checked or not, this works correctly): echo "<input type='radio' name='".$row['venue_id']."[]' value='1'".$checked."/>P1" echo "<input type='radio' name='".$row['venue_id']."[]' value='0'".$checked2." />P2"; I tried using the following: var_dump($_POST[$row]['game_id'][$iLine]); But this just returns a null value. Any ideas?