Avatar of Richard Korts
Richard KortsFlag for United States of America

asked on 

Oddly functioning php

I have this code

<?php
	error_reporting(E_ERROR);
	ini_set('session.cache_limiter','public');
	session_cache_limiter(false);
	session_start();
	include "db_connect_nb.php";
	$qry = "SELECT * from selections";
	$res = mysqli_query($link, $qry);
	$nr = mysqli_num_rows($res);
	echo " nr = " . $nr . "<br>";
	$nx = 0;
	for ($i = 0; $i < $nr; $i++) {
		if ($i == 0){
			echo "entered loop<br>";
		}	
		$s = mysqli_fetch_array($res,MYSQLI_ASSOC);
		$qryo = "select * from proj_opts where pid = " . $s['pid'] . " and ruid = " . $s['ruid'];
		echo "qry from opts " . $qryo . "<br>";
		$reso = mysqli_query($qryo);
		$npo = mysqli_num_rows($reso);
		echo "npo =  ". $npo . "<br>";
		if ($npo != 0) {
			$qryu = "UPDATE sel_opts set selno = " . $s['selno'] . " where pid = " . $s['pid'] . " and ruid = " . $s['ruid'];
			echo "qry for uptade sel_opts = " . $qryu;
			$resu = mysqli_query($link, $qryu);
			$nx++;
		}	
	}
	echo $nx  . " records updated.";
	exit;
		
?>	

Open in new window


Part of the output (of the echos) is in the attached file.

I cannot see why the other echos in the same loop underneath the ones that show do not show.

Any ideas?
prod_objs_update.JPG
PHP

Avatar of undefined
Last Comment
gr8gonzo
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

Often this kind of issue is explained by running different code to what you think you're running. I suggest making a minor tweak to one of the echo's that is displaying ok, in the file you think you're running, and then refreshing your browser page, and see if it displays.

eg change:
		echo "qry from opts " . $qryo . "<br>";

Open in new window

to:
		echo "qry2 from opts " . $qryo . "<br>";

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

You are not including your $link in the second query
line 19
$reso = mysqli_query($qryo);

Open in new window

Should be
$reso = mysqli_query($link,$qryo);

Open in new window

This is going to result in a null return from the mysqli_query which is not going to return any results for the num_rows call.

If you turn warnings on you will see the warnings pointing to the above.

EDIT:
Just re-read Gr8gonzo's comment and the above comment basically says exactly what he refers to. I am leaving this here as it gives code in the solution and highlights the point that had warnings been turned on it would have highlighted the issue.
Avatar of Richard Korts
Richard Korts
Flag of United States of America image

ASKER

Funny how the obvious illudes me sometimes.
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Happens to all of us. :)
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo