I have more than 10 lines like this and I want to echo just 5 rows per page this is my code.
$c = mysqli_fetch_field_direct;
$c1 = $c($result,2)->name;
$c2 = $c($result,3)->name;
$c3 = $c($result,4)->name;
//$cn,...;
echo "$row[2]" ; echo "$c1[2]";
echo "$row[3]" ; echo "$c1[3]";
//echo "$row[n]" , ...;
Before this code I have this:
$sql = "SELECT * FROM sheet1 WHERE id = '$_POST[text]'";
$result = mysqli_query($con,$sql);
If ($row = mysqli_fetch_array($result))
{
//the 10 lines of codes above
}
You may want to loop through these elements:
$sql = "SELECT * FROM sheet1 WHERE id = '$_POST[text]'";
$result = mysqli_query($con,$sql);
If ($row = mysqli_fetch_array($result))
{
for($i = 2; $i < 10; $i++){
$c = mysqli_fetch_field_direct($result,$i)->name;
echo $row[$i] ; echo $c[$i];
}
}
I have two tables i am using two quires to fetch data from them separately.
$query = mysql_query("SELECT * FROM offers");
$query1 = mysql_query("SELECT * FROM Offers_Dalia ") or die(mysql_error());
I am printing the result on one html-table.
.... the problem is that i want to know that why the loop is running for 11 times both.
1). I am using two while loops. 2). each loop is running for row->mysql_fetch_object times. please help me to find error why my both loops are running for 11 times. total 22 rows are present in html table output. but my both table have so many rows. 100 of rows in both table.
please check the code.
$query = mysql_query("SELECT * FROM offers");
$query1 = mysql_query("SELECT * FROM Offers_Dalia ") or die(mysql_error());
$x = 1;
$n = 0;
while($row = mysql_fetch_object($query))
{
$oid = $row->id;
$name = stripslashes($row->name);
$reward = stripslashes($row->credits);
$network = stripslashes($row->network);
$hits = $row->hits; //clicks; $epc = $row->epc;
$campid = stripslashes($row->campaign_id);
$country = $row->countries;
$url2=$row->link;
$desc=$row->description;
if($x%2 == 0)
{
$trColor = "f1f0f0";
}else
{
$trColor = "ffffff";
}
if(stristr($country, ","))
{
$country_arrs = explode(",", $country);
$country = implode(", ", $country_arrs);
}
?>
<tr style="background:#<?=$trColor?>" ><td><input type="checkbox" value="<?=$oid?>" name="ids[]" onclick="uncheckCheckAllbox(this)" /></td><td><?=$campid?>- campId</td><td><?=$name?></td><td><?=$reward?><td><?=$network?><td><?=$desc?></td><td>Click Here</td></td><td><?=$country?></td></tr>
$n++;
while($row1 = mysql_fetch_object($query1))
{
$uuid = $row1->offers_uuid;
$title1 = stripslashes($row1->title);
$info1 = stripslashes($row1->info_short);
$device_kind1 = stripslashes($row1->device_kinds);
$country1 = stripslashes($row1->target_groups_values);
// $status = toggleStatus($row->active);
$reward_dollar1 = $row1->reward_dollar; //clicks;
$url1 = $row1->url;
$network1 = 'Dalia';
$url1 = urldecode($url1);
if($x%2 == 0)
{
$trColor = "f1f0f0";
}else
{
$trColor = "ffffff";
}
if(stristr($country, ","))
{
$country_arrs = explode(",", $country);
$country = implode(", ", $country_arrs);
}
?>
<tr style="background:#<?=$trColor?>" ><td><input type="checkbox" value="" onclick="uncheckCheckAllbox(this)" /></td><td><?=$uuid?></td><td><?=$title1?></td><td><?=$reward_dollar1?></td><td><?=$network1?></td><td><?=$info1?></td><td>Click Here</td><td><?=$country1?></td></tr>
$n++;
$x++;
goto n;
}
n:
$x++;
}
In my php code below am trying to fetch a multiple text character from database and str_split each result output. add USED to the end line of each output and output remaining characters also i have tried:
require("init.php");
echo "<form action='reg.php' method='post'>
<b>booking code:</b><br />
<input type='text' name='book' size='17' />
<input type='submit' name='login' maxlength='2' size='2' value='PRINT OUT' />
</form>";
if(isset($_POST["login"]))
{
$book = mysqli_real_escape_string($conn, $_POST["book"]);
$sql = "SELECT `item_name` , `quantity` FROM `books` WHERE `book`='$book'"; $query = mysqli_query($conn, $sql);
while ($row1 = mysqli_fetch_array($query)) {
$d[] = $row1["item_name"];
$v[] = $row1["quantity"];
foreach($d as $r);
foreach($v as $ro);
$get = array(0 => array("yes" => $r, "no" => $ro));
foreach ($get as $item) {
$getd = $item["yes"];
}
$sql = mysqli_query($conn, "SELECT * FROM promo WHERE code='$getd' LIMIT 1");
while ($row = mysqli_fetch_array($sql)) {
$type = $row["name"];
$code = $row["recharge"];
$deta = $row["details"];
$logo = $row["logo"];
$price = $row["price"];
if(preg_match('/(xyz)/i', $type)) $type = "20";
if(preg_match('/(log)/i', $type)) $type = "16";
}
$id = $item["no"];
$result = str_split($code, $type);
$a = "";
$c = "";
for($b = 0; $b<$id; $b++)
{
$a .= $result[$b];
}
$b = "USED";
for($bn = $id; $bn<sizeof($result); $bn++){
$c .= $result[$bn];
}
echo $a.$b.$c;
}
}
}
and all my result output with code is unknow am saying all result all complecated result output thanks for your time and impact in my solutions
I am trying to echo last userID stored in MySQL. But it is not shown. No error is displayed.
I tried:
$stmti = $reg_user->runQuery("SELECT * FROM tbl_users");
$rowi = $stmti->fetch(PDO::FETCH_ASSOC);
$tf = $rowi['userID'];
echo $tf;
/* NOTE: This works only with mysqli
change the parameters "host","username","password","db_name" with your
own ones
*/
$link = mysqli_connect("host","username","password","db_name");
$query = " SELECT *
FROM tbl_users";
$rows = array();
$result = mysqli_query($link, $query);
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC))
$rows[] = $row;
$lastID = 0;
for ($i = 0 ; $i < count($rows) ; $i++)
$lastID = $i;
echo $rows[$lastID]["userID"];
try this :
$sth = $reg_user->prepare("SELECT MAX(userID) as userID FROM tbl_users");
$sth->execute();
$result = $sth->fetch(PDO::FETCH_ASSOC);
$tf= ($result['userID']);
echo $tf;
need some helps here: i try to import some excel sheets to my website, but the page keep loading and then stop working and showing internal server error text. the error log shows this caused by the import.php :Premature end of script headers: php-cgi, referer: ...file_import.php.
below are the codes:
<? include("../include/begin.inc.php");?>
<?
function showerror()
{
die("Error " . mysql_errno() . " : " . mysql_error());
}
function sava_data($array, $table){
$count = 0;
$total = 0;
foreach( $array as $tmp){
if ($count <> 0){
$date = date("Y:m:d H:i:s");
$sql = "INSERT INTO $table set ";
$sql .= "detail = '{$tmp[2]}', shape = '{$tmp[3]}', qty = '{$tmp[4]}', price = '{$tmp[5]}', percent = '{$tmp[6]}', colour = '{$tmp[7]}', clarity = '{$tmp[8]}', prop = '{$tmp[9]}', polish = '{$tmp[10]}', smy = '{$tmp[11]}', diam = '{$tmp[12]}', t_dep = '{$tmp[13]}', `table` = '{$tmp[14]}', fl = '{$tmp[15]}', colour_shade = '{$tmp[16]}', cert = '{$tmp[17]}', cert_no = '{$tmp[18]}', per_kg = '{$tmp[19]}', selling_price = '{$tmp[20]}', status = 'new', create_date = '{$date}'";
//echo $sql."<br>";
//exit();
if (!($result = #mysql_query($sql) or die("Error:" . mysql_error().$sql)))
showerror();
$total++;
}
$count++;
}
return $total;
}
function save_data2($array,$table){
$count = 0;
$total = 0;
foreach( $array as $tmp){
if ($count <> 0){
$date = date("Y:m:d H:i:s");
$sql = "INSERT INTO $table set ";
$sql .= "detail = '{$tmp[2]}', shape = '{$tmp[3]}', qty = '{$tmp[4]}', price = '{$tmp[5]}', percent = '{$tmp[6]}', colour = '{$tmp[7]}', clarity = '{$tmp[8]}', prop = '{$tmp[9]}', polish = '{$tmp[10]}', smy = '{$tmp[11]}', diam = '{$tmp[12]}', t_dep = '{$tmp[13]}', `table` = '{$tmp[14]}', fl = '{$tmp[15]}', colour_shade = '{$tmp[16]}', cert = '{$tmp[17]}', cert_no = '{$tmp[18]}', per_kg = '{$tmp[19]}', selling_price = '{$tmp[20]}', status = 'new', create_date = '{$date}'";
//echo $sql."<br>";
//exit();
if (!($result = #mysql_query($sql) or die("Error:" . mysql_error().$sql)))
showerror();
$total++;
}
$count++;
}
return $total;
}
function empty_data($table){
if($table == "fancy_table"){
$s3 = "select * from $table where file != ''";
$r3 = mysql_query($s3);
while($d3 = mysql_fetch_array($r3)){
$del_lo_l="../../_files/fancy_product/".$d3['file'];
if(file_exists($del_lo_l))
{
#unlink($del_lo_l);
}
}
}
$s4 = "truncate table `$table`";
mysql_query($s4);
$s5 = "OPTIMIZE TABLE `$table`";
mysql_query($s5);
}
//error_reporting(E_ALL ^ E_NOTICE);
$action = $_REQUEST['action'];
if($_POST){
if($action == "empty"){
empty_data("artwork");
}else if($action == "imported"){
$Import_TmpFile = $_FILES['file']['tmp_name'];
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('UTF-8');
$data->read($Import_TmpFile);
$total = 0;
//for ($i = 4; $i <= $data->sheets[0]['numRows']; $i++) {
for ($i = 4; $i <= 65536; $i++) {
if ($data->sheets[0]['cells'][$i][2] <> ""){
$sql = "INSERT INTO artwork set detail = '".$data->sheets[0]['cells'][$i][2]."', shape = '".$data->sheets[0]['cells'][$i][3]."', qty = '".$data->sheets[0]['cells'][$i][4]."', price = '".$data->sheets[0]['cells'][$i][5]."', percent = '".$data->sheets[0]['cells'][$i][6]."', colour = '".$data->sheets[0]['cells'][$i][7]."', clarity = '".$data->sheets[0]['cells'][$i][8]."', prop = '".$data->sheets[0]['cells'][$i][9]."', polish = '".$data->sheets[0]['cells'][$i][10]."', smy = '".$data->sheets[0]['cells'][$i][11]."', diam = '".$data->sheets[0]['cells'][$i][12]."', t_dep = '".$data->sheets[0]['cells'][$i][13]."', `table` = '".$data->sheets[0]['cells'][$i][14]."', fl = '".$data->sheets[0]['cells'][$i][15]."', colour_shade = '".$data->sheets[0]['cells'][$i][16]."', cert = '".$data->sheets[0]['cells'][$i][17]."', cert_no = '".$data->sheets[0]['cells'][$i][18]."', per_kg = '".$data->sheets[0]['cells'][$i][19]."', selling_price = '".$data->sheets[0]['cells'][$i][20]."', status = 'new', create_date = now()";
$result = #mysql_query($sql);
$total++;
}
}
echo $total;
//$total = sava_data($array, "artwork");
}else if($action == "fancy_imported"){
$Import_TmpFile = $_FILES['file']['tmp_name'];
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('UTF-8');
$data->read($Import_TmpFile);
$total = 0;
//for ($i = 4; $i <= $data->sheets[0]['numRows']; $i++) {
for ($i = 4; $i <= 65536; $i++) {
if ($data->sheets[0]['cells'][$i][2] <> ""){
$sql = "INSERT INTO fancy_style set detail = '".$data->sheets[0]['cells'][$i][2]."', artworktype = '".$data->sheets[0]['cells'][$i][3]."', shape = '".$data->sheets[0]['cells'][$i][4]."', qty = '".$data->sheets[0]['cells'][$i][5]."', colour = '".$data->sheets[0]['cells'][$i][6]."', cut = '".$data->sheets[0]['cells'][$i][7]."', measurements = '".$data->sheets[0]['cells'][$i][8]."', treatment = '".$data->sheets[0]['cells'][$i][9]."', origin = '".$data->sheets[0]['cells'][$i][10]."', comments = '".$data->sheets[0]['cells'][$i][11]."', cert = '".$data->sheets[0]['cells'][$i][12]."', cert_no = '".$data->sheets[0]['cells'][$i][13]."', `per_kg` = '".$data->sheets[0]['cells'][$i][14]."', status = 'new', create_date = now()";
$result = #mysql_query($sql);
$total++;
}
}
echo $total;
}else if($action == "fancy_empty"){
empty_data("fancy_style");
}
}
//exit();
jsRedirect(geturlname().".php?action=".$action."&rows=".$total);
?>
<? include("../include/end.inc.php");?>