php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9300 Having an array and other variables as parameters to a fonction
Submitted: 2001-02-16 10:50 UTC Modified: 2001-04-28 15:37 UTC
From: jean-philippe dot leveille at courrier dot usherb dot c Assigned:
Status: Closed Package: Arrays related
PHP Version: 4.0.4pl1 OS: Windows ME
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jean-philippe dot leveille at courrier dot usherb dot c
New email:
PHP Version: OS:

 

 [2001-02-16 10:50 UTC] jean-philippe dot leveille at courrier dot usherb dot c
Hi.

	function search_query($mot_recherche, $champs_de_recherche, $mot_complet = "") {
		if (empty($mot_complet)) $nouveau_mot_recherche = split(" ",$mot_recherche);
		else $nouveau_mot_recherche = $mot_recherche;
		$m = "";
		for($i=0; $i<count($nouveau_mot_recherche); $i++) {
			for ($j = 0; $j<count($champs_de_recherche); $j++) {
				$m .= $champs_de_recherche[$j]." LIKE '%".$nouveau_mot_recherche[$i]."%'";
				if ($j == (count($champs_de_recherche)-1)) {
					if ($i<(count($nouveau_mot_recherche)-1)) $m .= " OR ";
				}
				else $m .= " OR ";
			}
		}
		return $m;
	}

This fonction return a part of a MySQL query where I can search for any word of a sentence (contained in $mot_recherche which is copied to $nouveau_mot_recherche depending the value of $mot_complet. $mot_complet means (it is in french, sorry folks!) that if it is not empty, I want to search for the complete sentence in my DB.) I placed $mot_complet at the end of my argument so I don't always have to specify it. Fact is that $champs_de_recherche (which means field_of_search) that contains every field names I want to search in have an additionnal value that is $mot_complet. Imagine: if mot_complet equal "true", which means I want to search for a complete sentence in my DB, I'll have to search in every fields listed in $champs_de_recherche AND in the field name by the value of $mot_complet (where it is now "true"). So it will give me:

field LIKE '%$nouveau_mot_recherche%' OR... true LIKE '%nouveau_mot_recherche%'...

Understand what is the problem? I don't know if it is a real bug or if it's my code that is wrong. But having an array as a parameter in a fonction is useful and having additionnal values in this array that are every parameters declared after this array is abnormal.

I've search for a solution the documentation and it seems that there is no topic about this.

Anyway, I'm trying to modify my code so it will be working fine...

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-03-29 06:04 UTC] stas@php.net
Could you please give the isolated self-contained piece of
code that demonstrates the problem, and describe what it
should do, on your thinking, and what it does for you?
 [2001-04-28 15:37 UTC] derick@php.net
No feedback. If this problem persists with PHP 4.0.5 which
will be released next week, please reopen this report.

Derick
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC