Tsalagi Posted August 12, 2009 Share Posted August 12, 2009 Howdy. I"m trying to work with an API from Project Votes Smart but they have very little in the way of support and documentation. In the code example they provide there is a value already provided in the array located above the html code, which returns the information from the class it uses. There are two things that I'm stuck on. I would like to know how to populate a drop down list from their array and how to pass data from a search form to the array so I can display information provided by the class. For instance instead of the "stateId" provided in the example, I would like the user to enter a zip code and pass that to the array. They have a location class that uses a zip code array. Hope this isn't too confusing. Thanks for the help. <?php require_once("VoteSmart.php"); // Initialize the VoteSmart object $obj = new VoteSmart( 'CandidateBio.getBio', Array( 'candidateId' => 9026 )); // Get the SimpleXML object $x = $obj->getXmlObj(); echo ' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- pwned --> <html lang="en"> <body>'; // Check and make sure there is no error if (isset($x->errorMessage)) { // If there is, let's handle it echo ' <div>' . $x->errorMessage . '</div>'; } else { // If not, let's go -> // some quick and dirty assembly $candName = $x->candidate->firstName . ' ' . $x->candidate->middleName . ' ' . $x->candidate->lastName . ' ' . $x->candidate->suffix; if (!empty($x->candidate->photo)) $photo = '<img src="' . $x->candidate->photo . '" />'; echo ' <div> <a href="' . $x->generalInfo->linkBack . '">' . $x->generalInfo->title . '</a> </div> <br /><br /> <table> <tr> <td>Name</td><td>' . $candName . '</td> </tr><tr> <td>Birth</td><td>' . $x->candidate->birthDate . ' (' . $x->candidate->birthPlace . ')</td> </tr><tr> <td>Gender</td><td>' . $x->candidate->gender . '</td> </tr><tr> <td>Photo</td><td>' . $photo . '</td> </tr><tr> <td>Party</td><td>' . $x->office->parties . '</td> </tr><tr> <td>Office</td><td>' . $x->office->name . '</td> </tr> <tr><td>District</td><td>' . $x->branch->name . '</td> </tr> <tr><td>State</td><td>' . $x->office->title . '</td> </tr> '; } echo ' </body> </html>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/169857-api-connectivity/ Share on other sites More sharing options...
infiniteacuity Posted August 12, 2009 Share Posted August 12, 2009 Unless I'm missing something, it doesn't look like the code snippet provided applies to the problem you are describing. Quote Link to comment https://forums.phpfreaks.com/topic/169857-api-connectivity/#findComment-896477 Share on other sites More sharing options...
Tsalagi Posted August 12, 2009 Author Share Posted August 12, 2009 Unless I'm missing something, it doesn't look like the code snippet provided applies to the problem you are describing. My appologies. In my description I used "stateID" instead of "candidateID". Quote Link to comment https://forums.phpfreaks.com/topic/169857-api-connectivity/#findComment-896585 Share on other sites More sharing options...
Tsalagi Posted August 12, 2009 Author Share Posted August 12, 2009 Howdy. I"m trying to work with an API from Project Votes Smart but they have very little in the way of support and documentation. In the code example they provide there is a value already provided in the array located above the html code, which returns the information from the class it uses. There are two things that I'm stuck on. I would like to know how to populate a drop down list from their array and how to pass data from a search form to the array so I can display information provided by the class. For instance instead of the "stateId" provided in the example, I would like the user to enter a zip code and pass that to the array. They have a location class that uses a zip code array. Hope this isn't too confusing. Thanks for the help. <?php require_once("VoteSmart.php"); // Initialize the VoteSmart object $obj = new VoteSmart( 'CandidateBio.getBio', Array( 'candidateId' => 9026 )); // Get the SimpleXML object $x = $obj->getXmlObj(); echo ' <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <!-- pwned --> <html lang="en"> <body>'; // Check and make sure there is no error if (isset($x->errorMessage)) { // If there is, let's handle it echo ' <div>' . $x->errorMessage . '</div>'; } else { // If not, let's go -> // some quick and dirty assembly $candName = $x->candidate->firstName . ' ' . $x->candidate->middleName . ' ' . $x->candidate->lastName . ' ' . $x->candidate->suffix; if (!empty($x->candidate->photo)) $photo = '<img src="' . $x->candidate->photo . '" />'; echo ' <div> <a href="' . $x->generalInfo->linkBack . '">' . $x->generalInfo->title . '</a> </div> <br /><br /> <table> <tr> <td>Name</td><td>' . $candName . '</td> </tr><tr> <td>Birth</td><td>' . $x->candidate->birthDate . ' (' . $x->candidate->birthPlace . ')</td> </tr><tr> <td>Gender</td><td>' . $x->candidate->gender . '</td> </tr><tr> <td>Photo</td><td>' . $photo . '</td> </tr><tr> <td>Party</td><td>' . $x->office->parties . '</td> </tr><tr> <td>Office</td><td>' . $x->office->name . '</td> </tr> <tr><td>District</td><td>' . $x->branch->name . '</td> </tr> <tr><td>State</td><td>' . $x->office->title . '</td> </tr> '; } echo ' </body> </html>'; ?> This issue has been solved by passing values to avariable with a form thanks Quote Link to comment https://forums.phpfreaks.com/topic/169857-api-connectivity/#findComment-896821 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.