PDA

View Full Version : How do I redirect from my module if query fails?


mccollin
06-01-2007, 08:33 PM
I am building a CMPS module that will let me dynamically build a page from GARS custom fields, so that I can have one page definition and generate hundreds of pages from it. I have it all working, but I need to now put in some error detection. I am passing a url value that is used to find the correct thread. If someone inputs a bogus value, then it takes me into a messy end result... here is the framework I am working with...

$device = $vbulletin->input-clean_gpc('r', 'd', TYPE_NOHTML);

$sql = "SELECT statement...
WHERE .... AND gcv.gars36 = '$device' ";

$result = $db->query_read($sql);

while ($result = $db->fetch_array($results))
{
..........
}


The value that is passed into $device is supposed to match one unique thread. If the value is bogus, nothing is found. How can I detect that I retrieved no rows and immediately redirect to another url without continuing the module?

Assuming I can do that, is there a way to also do the redirect if I return more than one row?

harmor19
06-01-2007, 08:44 PM
After you do the SQL query add.

if(mysql_error())
{
//error
}

mccollin
06-01-2007, 09:22 PM
Well, I'm not sure it is going to produce an error... by fail, I meant to say that it didn't find anything. If it doesn't find anything, then all the data for the rest of the module and templates won't exist and so the result is just a big mess. I do have some follow-on queries in some of the modules that will fail, but I'd like to catch it at the source, and redirect to another page in vbulletin. I tried a count() on the array, but it doesn't seem to work for me. I guess I'll have to stick something in the data that I can test for... I was hoping there was an easy way to determine if I didn't find any rows, and then just bale out.

Assuming that is figured out... how can I redirect out of this module? Is there some vBulletin function that would let me go elsewhere with a call? Or, do I need to call a template and build the contents with static data? I was hoping to just call a different page.

Dismounted
06-02-2007, 07:33 AM
$db->num_rows == 0