Jump to content


Member Since 06 May 2003
Offline Last Active Yesterday, 11:55 PM

Posts I've Made

In Topic: PDO version of num_rows?

Yesterday, 10:37 PM

Unless you are writing portable code that runs on pseudo databases for some reason, there isn't much of a concern. Don't misinterpret that warning. If you are writing specifically to mysql, it is going to work fine.

For select statements you can always do this, although it's lots of extra overhead:

SELECT count(*) as countof FROM ... WHERE etc.

This query will always return a result that contains your number of rows to be returned in the next query, even if that number is zero.

Of course you have to author these queries for every SELECT statement which few people want to do, but it's an alternative to doing the query and relying on the client result set feature that provides num_rows, or using Mac's idea. In cases of large datasets that need to be paginated, Mac's work around would be bad.

In Topic: Help with creating an Unsubscribe PHP page.

Yesterday, 10:27 PM

You either have a list or you don't. If you don't have an email list there is nothing to unsubscribe from.

In Topic: Notice: Array to String Conversion in c:\xampp\httpdocs\websit...

Yesterday, 10:24 PM

Spousename, SpouseAddress, etc, are arrays because this is an application for Mormons?

I joke, but in order to understand how many times you need to loop, as well as reference the array elements, I would need to better understand what the data would look like in the case there are multiple entries.

I don't see the correlation between the possible arrays that leads to individual rows of data where some of the data is the same, and other data would vary.

Probably in this circumstance you would want to write a function that builds a $rowData[] array where you have everything you need to do your inserts and then you would for loop through that array doing a prepare/execute for each array element.

Just strictly answering your question, is basically me showing how you reference data in a numerically indexed array.

One way is to use a for .. loop, another is a foreach. I really can't figure out from your code or your description which is appropriate.

With that said, simplistically:

if (is_array($_POST['sourcename'])) {
$count = count($_POST['sourcename']);
for ($x = 0; $x < $count; $x++) {
echo "{$_POST['sourcename']} <br>";

As you will see from that (or from var_dump() of the various POST arrays, you will have a simple array of strings, that can be addressed numerically starting at zero.

echo $_POST['sourcename'][0]; // first element
echo $_POST['sourcename'][1]; // 2nd element etc.

As I stated, the problem is that some of the fields could have 3 elements, while others have 5, or 1. Your database structure seems to be flat, but it's also unclear how the data is related on a row by row basis.

In Topic: Where can I donate to phpfreaks?

Yesterday, 10:03 PM

I kind of gathered that.  I have donated in the past.  I would just like to show my support even though $100 really isn't much in the grand scheme of things and it certainly wouldn't pay for all the help that I have received.
A big thank you to whomever it is that runs this website.

The site itself is owned by a server hosting company named Infinitum Technology, who operates their hosting business as http://www.rapidvps.com/. They purchased the site from the originator a few years ago.

RapidVPS provides the server and bandwidth for the site, and also receives any advertising related income it might be earning.

The content of the site has always been administered, moderated and otherwise provided for free by volunteers. Many of those volunteers will accept a donation, but if not, don't worry about it.

We rarely receive thanks, so it's always nice to know that people are being helped here, as this is the primary reason that most of the people who answer questions do so altruistically and with the desire to give something back to the PHP developer community, not to mention the primarily volunteer PHP project participants.

We want PHP to continue to thrive and grow, and for many of us phpfreaks is our way of contributing to that effort.

In Topic: Notice: Array to String Conversion in c:\xampp\httpdocs\websit...

Yesterday, 09:51 PM

Yes well when you define an html form element as an array, it can have multiple values and will be an array when converted to an internal PHP variable.

For example, you have:

<input type="hidden" name="sourcename[]" value="<?php echo $_POST['sourcename' . $id]; ?>">

It's not really clear why you have some fields defined as arrays and others that are not. I can't comment on that, but it's fishy.

In order to figure out what you have there are things like is_array() in php.

if (is_array($_POST["sourcename"])) {


It seems to me if this is a multiple line item type application, then it ought to be all or none for the fields in the POST. Once you've detected that those are arrays rather than simple strings, you will need to loop on the section of code that binds and then executes the queries. With mysqli_ you don't have to prepare the query again, but only bind the values and then execute the query.