Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

without editing the core code, add values from mysqli to the array

I am using mysqli

this query itterates through the messages I want to delete
select * from search where wrong=1


but it has to fit the config file

$config['username_to_delete_message'] = array("user1","user2","user3");


I do not want to edit the core code

I am adding mysqli to the config file
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Maybe something like this pidgin code?

foreach ($config['username_to_delete_message'] as $u)
{
    DELETE FROM seach WHERE user='$u' AND wrong=1
}

If you can post the test data and the CREATE TABLE scripts we might be able to avoid the guesswork and show you a more dependable answer.
Avatar of rgb192

ASKER

create table search(
search_id int auto_increment primary key,
profile_id varchar(20),
wrong int
);



the config file is the only file I want to edit
currently the config file has this variable

$config['username_to_delete_message'] = array("user1","user2","user3");

I think I want the array to fit this pattern:
array("user1","user2","user3")

I am sure that the answer is
$config['username_to_delete_message'] = array(list of users goes here);


no need to put a delete statement because I think the delete is in the core file



mysqli_connect
<?php # Script 16.4 - mysqli_connect.php

// This file contains the database access information. 
// This file also establishes a connection to MySQL 
// and selects the database.

// Set the database access information as constants:

DEFINE ('DB_USER', 'user');
DEFINE ('DB_PASSWORD', 'password');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'dbname');


// Make the connection:
$dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

if (!$dbc) {
  trigger_error ('Could not connect to MySQL: ' . mysqli_connect_error() );
  echo "not connected";
}else{
//echo "connected";
}
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

Open in new window





include('mysqli_connect');
$used_table='search';          
$qcheck ='select '.$used_table.'_id from '.$used_table.' where profile_id=\''.trim($contact_name).'\' ;';
$rcheck =$mysqli->query($qcheck);
$search_id='';
while ($rowcheck=$rcheck->fetch_object()){
  $search_id=$rowcheck->search_id;
}

Open in new window

http://www.laprbass.com/RAY_temp_rgb192.php

Outputs:

array(1) {
  ["username_to_delete_message"]=>
  array(3) {
    [0]=>
    string(5) "user1"
    [1]=>
    string(5) "user2"
    [2]=>
    string(5) "user3"
  }
}

<?php // RAY_temp_rgb192.php
error_reporting(E_ALL);
$config['username_to_delete_message'] = array("user1","user2","user3");
var_dump($config);

Open in new window

Please clarify the question, thanks.
Avatar of rgb192

ASKER

yes, that is the correct var_dump for the config file
Avatar of rgb192

ASKER

>>Please clarify the question, thanks.

how can I pass the array
mysqli  "select search_id from search"

to the variable
$config['username_to_delete_message']
Avatar of rgb192

ASKER

The only thing I could do is

while ($rowcheck=$rcheck->fetch_object()){
  $variable.=' " '.$rowcheck->search_id.' ", ';
}
and strip out the last comma

$config['username_to_delete_message']=$variable;


But you always have a better solution :)
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgb192

ASKER

first checking with var_dump as you advised

I saw that
 $variable[] = $rowcheck->search_id;

$config['username_to_delete_message'] = $variable;


is the same as manually creating a comma separated list,

so your answer was better than my automatically creating and with quotes and commas rtriming the last comma of a automatically created list

thanks