Page 1 of 1

How to show every single THANG ??

Posted: Tue Feb 22, 2011 4:05 pm
by Vinnar
hay wut's happening forum?

so i am currently working on a mailing list and its function is to send EVERY single user a notification email once an entry they are looking for on a database is available

below is the mailing_list.php which sets up database connection and deals with the fields of the table:

Code: Select all


<?php
include('view_function.php');
global $connect;
$connect = mysqli_connect("localhost", "", "") or die(mysqli_error($connect));
$error = mysqli_error($connect);
$db_select = mysqli_select_db($connect, "");

$select5 = "SELECT LS_CELL_TYPE FROM link_specificities
INNER JOIN links ON link_specificities.LS_LINK = links.L_ID
WHERE links.L_ID = $LinkID";
$get5 = mysqli_query($connect, $select5) or die(mysqli_error($connect));
while ($row5 = mysqli_fetch_array($get5)){

extract($row5);

$cellType = $row5['LS_CELL_TYPE'];

}

$select6 = "SELECT CT_NAME FROM cell_type WHERE CT_ID = '$cellType'";
$get6 = mysqli_query($connect, $select6) or die(mysqli_error($connect));

$i = 0;
while ($row6 = mysqli_fetch_array($get6)){

extract($row6);

$query[$i] = $row6['CT_NAME'];
$check = "select first_name, email from mailing_list WHERE query = '$query[$i]'";
$i++;
echo $query;
}
update($check);

?>


And below is the view_function.php that's included above:

Code: Select all


<?php

function update($check){
global $query;
global $connect;
global $LinkID;

$result = mysqli_query($connect, $check) or die(mysqli_error($connect));

while ($row3 = mysqli_fetch_array($result)){

extract($row3);

$fname = $row3['first_name'];
$email = $row3['email'];

$to = "$fname <$email>";
$subject = "The query is updated.";
$headers = "From: asdfasdfasdf";
$body = "
Hello $fname,\r\n\nThis is to inform you that $query is updated, please go to this link to search for it:\r\n\nhttp:/asdfasdfasdfasdf/view/View.php?LinkID=$LinkID \r\n\nRegards,\r\n\";
if(send_email($to,$subject,$body,$headers)){
//there are no errors, return empty array
$errors = array();
} else {
$errors[] = "Server error, mail could not be sent.";
}

}
}
?>


As you can c in mailing_list.php, i echoed out $query, but it only echoed ONE result of that entire array

so wut i am trying to do is to make a while loop with a counter in it, but still only one result shows up

Basically, i want the $query to output all items in an array so that following SELECT statement can choose the item which matches the required query and send the users the notification email bout such particular query

How should i fix it in order to do just that?

Thx :wink:

Re: How to show every single THANG ??

Posted: Wed Feb 23, 2011 3:52 pm
by Vinnar
help plzzzzzzzzzzzzzz

Re: How to show every single THANG ??

Posted: Wed Feb 23, 2011 4:32 pm
by pickle
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.

Some examples of what not to do are ne1, any1 (anyone); u (you); ur (your or you're); 2 (to too); prolly (probably); afaik (as far as I know); etc.
Not trying to be a jerk, but maybe if you wrote more clearly, people would read your question.

Also, thank you for waiting (almost) 24 hours to bump as per the forum rules, rather than the 2 or 3 hours that most people wait.

Re: How to show every single THANG ??

Posted: Thu Feb 24, 2011 8:40 am
by Vinnar
k that helps a lot .....

but dude i can't help it, it's internet buddy, i dun really understand if i can't even use u as you ....

anyway

ok let me clarify the question

In mailing_list.php, wut i am trying to do is to who all the queries from the Cell_type array, but it seems the while loop fails and only one query echoed out when i tested it

so how to properly fix the while loop ?

Re: How to show every single THANG ??

Posted: Thu Feb 24, 2011 9:48 am
by pickle
Just because it's the Internet is no excuse for bad English. The work you "save" by not having to type real words is transferred to the reader - the people you're trying to get help from. It's in your best interest to make things as easy for us as possible. Plus - can you imagine trying to understand a question in a second language, when a bunch of the words aren't even spelled right?

Now, to answer your question, you do have some errors in your code:

Code: Select all

//not necessary: $i = 0;
while ($row6 = mysqli_fetch_array($get6)){

  //not necessary.  extract() just takes all the elements in $row6 and makes them local variables.  This serves no purpose here
  //extract($row6);

  //don't need the $i - you can just use [] since you're writing to the array: $query[$i] = $row6['CT_NAME'];
  $query[] = $row6['CT_NAME'];
  $check = "select first_name, email from mailing_list WHERE query = '$query[$i]'";
  //again, not necessary: $i++;
  echo $query;//since $query is an array, all you'll get output is "array"
}

Re: How to show every single THANG ??

Posted: Fri Feb 25, 2011 9:15 am
by Vinnar
k thx for the reply, but apparently i can't use $query[] since the following error pops up

Fatal error: [] operator not supported for strings

Also, if the counter is not necessary, then how should i fix the following line:

$check = "select first_name, email from mailing_list WHERE query = '$query[$i]'";

do i eliminate $i all together?

thanks

Re: How to show every single THANG ??

Posted: Fri Feb 25, 2011 9:41 am
by pickle
Somewhere you're initializing $query as a string, which stops you from being able to treat it like an array in this way. Somewhere before view_function.php - because that's where you import the global $query.

In your current setup, it doesn't look like $query needs to be an array at all. In each iteration of your while() loop, you overwrite the value of $check with the content of the currently looped row - so $query doesn't need to be able to store multiple values. Does $check need to be an array though?